package com.bj58.groupbuy.action.controllers;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.springframework.web.bind.ServletRequestUtils;

import com.bj58.groupbuy.action.charts.EChartsUtils;
import com.bj58.groupbuy.action.charts.NullResult;
import com.bj58.groupbuy.action.interceptors.Check;
import com.bj58.groupbuy.action.model.BelongLocal;
import com.bj58.groupbuy.action.model.ChinahrIndustry;
import com.bj58.groupbuy.action.model.ChinahrJob;
import com.bj58.groupbuy.action.model.ChinahrSource;
import com.bj58.groupbuy.action.model.DisplayLocal;
import com.bj58.groupbuy.action.model.IRColumns;
import com.bj58.groupbuy.action.model.IRDbConfig;
import com.bj58.groupbuy.action.model.IRDrillConfig;
import com.bj58.groupbuy.action.model.IRReport;
import com.bj58.groupbuy.action.model.IRSearchConfig;
import com.bj58.groupbuy.action.model.IRSearchType;
import com.bj58.groupbuy.action.model.IRSubMailVo;
import com.bj58.groupbuy.action.model.InfoSourcePlatform;
import com.bj58.groupbuy.action.model.JxedtFlowSource;
import com.bj58.groupbuy.action.model.Menu;
import com.bj58.groupbuy.action.model.NetFlowSource;
import com.bj58.groupbuy.action.model.NewBelongCate;
import com.bj58.groupbuy.action.model.NewDisplayCate;
import com.bj58.groupbuy.action.model.OperMenu;
import com.bj58.groupbuy.action.model.User;
import com.bj58.groupbuy.action.model.UserSubMailVo;
import com.bj58.groupbuy.action.service.BelongLocalService;
import com.bj58.groupbuy.action.service.ChinahrIndustryService;
import com.bj58.groupbuy.action.service.ChinahrJobService;
import com.bj58.groupbuy.action.service.ChinahrSourceService;
import com.bj58.groupbuy.action.service.DisplayLocalService;
import com.bj58.groupbuy.action.service.IRColumnsService;
import com.bj58.groupbuy.action.service.IRDbConfigService;
import com.bj58.groupbuy.action.service.IRDrillConfigService;
import com.bj58.groupbuy.action.service.IRReportService;
import com.bj58.groupbuy.action.service.IRSearchConfigService;
import com.bj58.groupbuy.action.service.IRSearchTypeService;
import com.bj58.groupbuy.action.service.InfoSourcePlatformService;
import com.bj58.groupbuy.action.service.IntReportMainService;
import com.bj58.groupbuy.action.service.JxedtFlowSourceService;
import com.bj58.groupbuy.action.service.MenuService;
import com.bj58.groupbuy.action.service.NetFlowSourceService;
import com.bj58.groupbuy.action.service.NewBelongCateService;
import com.bj58.groupbuy.action.service.NewDisplayCateService;
import com.bj58.groupbuy.action.service.UserOperService;
import com.bj58.groupbuy.action.templateParse.IRTemplateParse;
import com.bj58.groupbuy.action.util.DateUtil;
import com.bj58.groupbuy.action.util.ExcelUtilNew;
import com.bj58.groupbuy.action.util.MyPathUtil;
import com.bj58.groupbuy.action.util.MyStore;
import com.bj58.groupbuy.action.util.SomePublicUtil;
import com.bj58.groupbuy.action.util.SortUtil;
import com.bj58.groupbuy.action.util.TemplateMethodFactory;
import com.bj58.groupbuy.action.util.VelocityTools;
import com.bj58.groupbuy.service.locator.ServiceLocator;
import com.bj58.groupbuy.util.IOUtils;
import com.bj58.groupbuy.wf.page.Paginate;
import com.bj58.wf.mvc.ActionResult;
import com.bj58.wf.mvc.BeatContext;
import com.bj58.wf.mvc.BeatContext.Model;
import com.bj58.wf.mvc.MvcController;
import com.bj58.wf.mvc.actionresult.ContentResult;
import com.bj58.wf.mvc.annotation.GET;
import com.bj58.wf.mvc.annotation.POST;
import com.bj58.wf.mvc.annotation.Path;

/**自定义报表
 * @author huangliang
 *
 */
@Path("intreport")
public class IntReportController  extends MvcController{
	private IRReportService iRReportService = ServiceLocator.get(IRReportService.class);
	private IRDbConfigService IRDbConfigService = ServiceLocator.get(IRDbConfigService.class);
	private IRSearchTypeService IRSearchTypeService = ServiceLocator.get(IRSearchTypeService.class);
	private IntReportMainService IntReportMainService = ServiceLocator.get(IntReportMainService.class);
	private SomePublicUtil spu = new SomePublicUtil();
	private IRTemplateParse  tp = new IRTemplateParse();
	private IRSearchConfigService IRSearchConfigService = ServiceLocator.get(IRSearchConfigService.class);
	private IRDrillConfigService IRDrillConfigService = ServiceLocator.get(IRDrillConfigService.class);
    private VelocityTools  tools = new VelocityTools();
	private IRColumnsService IRColumnsService = ServiceLocator.get(IRColumnsService.class);
	private DisplayLocalService displayLocalService = ServiceLocator.get(DisplayLocalService.class);
	private BelongLocalService belongLocalService = ServiceLocator.get(BelongLocalService.class);
	private MenuService menuService = ServiceLocator.get(MenuService.class);
//	private FusionChartsUtil  fcu = new FusionChartsUtil();
	private NewDisplayCateService newDisplayCateService = ServiceLocator.get(NewDisplayCateService.class);
	private NewBelongCateService newBelongCateService = ServiceLocator.get(NewBelongCateService.class);
	private InfoSourcePlatformService infoSourcePlatformService = ServiceLocator.get(InfoSourcePlatformService.class);
	private NetFlowSourceService netFlowSourceService = ServiceLocator.get(NetFlowSourceService.class);
	private UserOperService userOperService = ServiceLocator.get(UserOperService.class);
	private JxedtFlowSourceService jxedtFlowSourceService = ServiceLocator.get(JxedtFlowSourceService.class);
	private ChinahrSourceService chinahrSourceService = ServiceLocator.get(ChinahrSourceService.class);
	private ChinahrIndustryService chinahrIndustryService = ServiceLocator.get(ChinahrIndustryService.class);
	private ChinahrJobService chinahrJobService = ServiceLocator.get(ChinahrJobService.class);
	
	/**自定义报表管理
	 * @return
	 */
	@Path("irmain/{state}")
	@Check("intreport/irmain/irmanager")
	@POST
	@GET
	public ActionResult relateTag (String state){
		HttpServletRequest request = beat.getRequest();
		Model model= beat.getModel();
		String returnUrl ="";
		TemplateMethodFactory.setVelocityContext("tools", VelocityTools.class, model);
		try{
			if("irmanager".equals(state)){  //报表管理主页面
				//报表管理页
				String reportName = ServletRequestUtils.getStringParameter(request, "reportName","");
				String reportCate1 = ServletRequestUtils.getStringParameter(request, "reportCate1","");
				String reportCate2 = ServletRequestUtils.getStringParameter(request, "reportCate2","");
				
				int pageIndex = ServletRequestUtils.getIntParameter(request, "pageindex", 0);
				//查询条件组织 以及分页查询参数组织
				StringBuffer where = new StringBuffer(); //查询条件
				StringBuffer url = new StringBuffer(); //分页查询参数
				where.append(" state(0,1)  ");
				if(!"".equals(reportName)){
					where.append(" & reportName ? '%"+reportName+"%'");
					url.append("&reportName="+reportName);
				}
				if(!"".equals(reportCate1)){
					where.append(" &  reportCate1 ? '%"+reportCate1+"%'");
					url.append("&reportCate1="+reportCate1);
				}
				if(!"".equals(reportCate2)){
					where.append(" &  reportCate2 ? '%"+reportCate2+"%'");
					url.append("&reportCate2="+reportCate2);
				}
				//分页查询
				Paginate<IRReport> pList = iRReportService.getReportListByCon(pageIndex, 50, where.toString());
				model.add("pList",pList);
				model.add("rsList",pList.getItems());	
				model.add("paramurl",url.toString());
				model.add("reportName",reportName);
				model.add("reportCate1",reportCate1);
				model.add("reportCate2",reportCate2);
				model.add("pageIndex",pageIndex);
				returnUrl = "intreport/irmanager";
			}else if("changestate".equals(state)){ //报表状态修改
				try{
					int id = ServletRequestUtils.getIntParameter(request, "id", 0);
					int upstate = ServletRequestUtils.getIntParameter(request, "upstate", -1);
					if(id == 0 || upstate == -1){
						return new ContentResult("error");
					}
					if(IntReportMainService.updateReportState(id, upstate)){
						return new ContentResult("success");
					}else{
						return new ContentResult("error");
					}
				}catch (Exception e) {
					e.printStackTrace();
					return new ContentResult("error");
				}
			}else if("editreport".equals(state)){ //报表编辑界面
				int id = ServletRequestUtils.getIntParameter(request, "id", 0);
				IRReport  report = iRReportService.getById(id);
				List<IRColumns> columnList = IRColumnsService.getColsByReportId(id);
				String strTabName="";
				List<String> tabNameList = new ArrayList<String>();
				for(IRColumns col: columnList){
					String tabType = col.getTabType();
					if(tabType==null || "".equals(tabType.trim())){
						tabType="指标";
						col.setTabType("指标");
					}
					if(!tabNameList.contains(tabType)){
						tabNameList.add(tabType);
						strTabName +=tabType+";";
					}
				}
				Collections.sort(tabNameList);
				model.add("strTabName",strTabName);
				model.add("tabNameList",tabNameList);
				List<IRSearchConfig> searchConfigList = IRSearchConfigService.getListByIRid(id);
				List<IRDrillConfig> drillConfigList = IRDrillConfigService.getListByIRid(id);
				List<IRDbConfig> dbList = IRDbConfigService.getAllDb();  //数据库列表
				List<IRSearchType>  searchTypeList = IRSearchTypeService.getReportListByCon("");
				StringBuffer  selectValue = new StringBuffer();
				for(IRSearchType  vo : searchTypeList){  //查询类型列表
					selectValue.append("<option value='"+vo.getId()+"' >"+vo.getName()+"</option>");
				}
				model.add("selectValue",selectValue);
				model.add("searchTypeList",searchTypeList);
				model.add("report",report);
				model.add("columnList",columnList);
				model.add("drillConfigList",drillConfigList);
				model.add("searchConfigList",searchConfigList);
				model.add("dbList",dbList);
				
				returnUrl = "intreport/editreport";
			}else if("toaddnewreport".equals(state)){ //新增报表
				List<IRDbConfig> dbList = IRDbConfigService.getAllDb();  //数据库列表
				model.add("dbList",dbList);
				
				List<IRSearchType>  searchTypeList = IRSearchTypeService.getReportListByCon("");
				model.add("searchTypeList",searchTypeList);
				//查询类型内容...
				StringBuffer  selectValue = new StringBuffer();
				for(IRSearchType  vo : searchTypeList){
					selectValue.append("<option value='"+vo.getId()+"' >"+vo.getName()+"</option>");
				}
				model.add("selectValue",selectValue);
				returnUrl = "intreport/addreport";
			}
		}catch (Exception e) {
			e.printStackTrace();
		}
		return ActionResult.view(returnUrl);
	}	
	
	
	/** 增加新报表
	 * @return
	 */
	@Path("addnewreport")
	@Check("intreport/irmain/irmanager")
	@POST
	@GET
	public ActionResult addNewReport (){
		HttpServletRequest request = beat.getRequest();
		try{
			User user = spu.getUserByCookie(request);
			IRReport  irReport = new IRReport();
			Menu  menu = new Menu();
			//报表基本信息  && menu
			String[] reportBaseInfos = ServletRequestUtils.getStringParameters(request, "reportBaseInfo");
			if(reportBaseInfos.length == 0){
				return new ContentResult("error");
			}else{
				//报表信息
				irReport.setReportName(reportBaseInfos[0]);
				irReport.setDBconfig(Integer.parseInt(reportBaseInfos[1]));
				irReport.setTableName(reportBaseInfos[2]);
				irReport.setReportCate1(reportBaseInfos[3]);
				irReport.setReportCate2(reportBaseInfos[4]);
				irReport.setTemplateType(Integer.parseInt(reportBaseInfos[5]));
				irReport.setDescription(reportBaseInfos[6]);
				irReport.setCreater(user.getUsername());
				irReport.setCreatTime(DateUtil.getStringDate(new Date(), "yyyy-MM-dd HH:mm:ss"));
				irReport.setState(1);
				
				int isMonthSearch = ServletRequestUtils.getIntParameter(request, "isMonthSearch", 1);//是否支持跨月查询
				irReport.setIsMonthSearch(isMonthSearch);
				//菜单信息
				menu.setName(reportBaseInfos[0]);
				menu.setCate1(reportBaseInfos[3]);
				menu.setCate2(reportBaseInfos[4]);
				menu.setIsshow(1);
			}
			
			
			//报表筛选条件配置(ir_searchconfig)
			List<IRSearchConfig>  ircList = new ArrayList<IRSearchConfig>();
			int searchcount =  ServletRequestUtils.getIntParameter(request, "searchcount", 0);
			if(searchcount == 0){
				return new ContentResult("error");
			}
			for(int i = 1 ; i <= searchcount ; i++){
					String requestName = "searchInfo"+i;
					String[] searchInfos = ServletRequestUtils.getStringParameters(request, requestName);
					if(searchInfos.length == 0){
						continue;
					}
					IRSearchConfig  vo  = new IRSearchConfig();
					vo.setSearchTypeId(Integer.parseInt(searchInfos[0]));
					vo.setSename(searchInfos[1]);
					vo.setScname(searchInfos[2]);
					vo.setDetailValue(searchInfos[3]);
					ircList.add(vo);
			}
			//钻取关联配置(ir_drillconfig)
			List<IRDrillConfig>  irdList = new ArrayList<IRDrillConfig>();
			int drillcount =  ServletRequestUtils.getIntParameter(request, "drillcount", 0);
			for(int i = 1 ; i <= drillcount ; i++){
					String requestName = "drillInfo"+i;
					String[] drillInfos = ServletRequestUtils.getStringParameters(request, requestName);
					if(drillInfos.length == 0){
						continue;
					}
					IRDrillConfig  vo  = new IRDrillConfig();
					vo.setDrillname(drillInfos[0]);
					vo.setReplayname(drillInfos[1]);
					irdList.add(vo);
			}
			//查询指标配置
			List<IRColumns>  colList = new ArrayList<IRColumns>();
			int colcount =  ServletRequestUtils.getIntParameter(request, "colcount", 0);
			for(int i = 1 ; i <= colcount ; i++){
					String requestName = "colinfo"+i;
					String[] colinfos = ServletRequestUtils.getStringParameters(request, requestName);
					if(colinfos.length == 0){
						continue;
					}
					IRColumns vo = new IRColumns();
					vo.setEname(colinfos[0]);
					vo.setCname(colinfos[1]);
					vo.setTabType(colinfos[2]);
					vo.setSpecialInSql(colinfos[3]);
					vo.setColType(Integer.parseInt(colinfos[4]));
					vo.setIsOrderBy(Integer.parseInt(colinfos[5]));
					colList.add(vo);
			}
			
			boolean result = IntReportMainService.saveNewReport(irReport, menu, ircList, colList,irdList);
			if(!result){
				return new ContentResult("error");
			}
		}catch (Exception e) {
			e.printStackTrace();
			return new ContentResult("error");
		}
		return new ContentResult("success");
	}	
	
	/** 更新报表
	 * @return
	 */
	@Path("updatereport")
	@Check("intreport/irmain/irmanager")
	@POST
	@GET
	public ActionResult updateReport (){
		HttpServletRequest request = beat.getRequest();
		try{
			//报表基本信息  && menu
			IRReport  irReport = null;
			Menu  menu = null;
			String[] reportBaseInfos = ServletRequestUtils.getStringParameters(request, "reportBaseInfo");
			if(reportBaseInfos.length == 0){
				return new ContentResult("error");
			}else{
				//报表信息
				irReport = iRReportService.getById(Integer.parseInt(reportBaseInfos[0]));
				
				irReport.setReportName(reportBaseInfos[1]);
				irReport.setDBconfig(Integer.parseInt(reportBaseInfos[2]));
				irReport.setTableName(reportBaseInfos[3]);
				irReport.setReportCate1(reportBaseInfos[4]);
				irReport.setReportCate2(reportBaseInfos[5]);
				irReport.setTemplateType(Integer.parseInt(reportBaseInfos[6]));
				irReport.setDescription(reportBaseInfos[7]);
				
				int isMonthSearch = ServletRequestUtils.getIntParameter(request, "isMonthSearch", 1);//是否支持跨月查询
				irReport.setIsMonthSearch(isMonthSearch);
				/*int isDaySearch = ServletRequestUtils.getIntParameter(request, "isDaySearch", 0);//是否按日成表查询
				irReport.setIsDaySearch(isDaySearch);*/
				//菜单信息
				menu = menuService.findById(Menu.class, irReport.getMenuId());
				menu.setName(reportBaseInfos[1]);
				menu.setCate1(reportBaseInfos[4]);
				menu.setCate2(reportBaseInfos[5]);
				//更新menu里action的路径的模板版本号
				int edId = Integer.parseInt( menu.getAction().split("_")[1])+1;
				menu.setAction(menu.getAction().split("_")[0]+"_"+edId);
				
			}
			
			
			//报表筛选条件配置(ir_searchconfig)
			List<IRSearchConfig>  ircList = new ArrayList<IRSearchConfig>();
			int searchcount =  ServletRequestUtils.getIntParameter(request, "searchcount", 0);
			if(searchcount == 0){
				return new ContentResult("error");
			}
			for(int i = 1 ; i <= searchcount ; i++){
					String requestName = "searchInfo"+i;
					String[] searchInfos = ServletRequestUtils.getStringParameters(request, requestName);
					if(searchInfos.length == 0){
						continue;
					}
					IRSearchConfig  vo  = new IRSearchConfig();
					vo.setSearchTypeId(Integer.parseInt(searchInfos[0]));
					vo.setSename(searchInfos[1]);
					vo.setScname(searchInfos[2]);
					vo.setDetailValue(searchInfos[3]);
					ircList.add(vo);
			}
			//钻取关联配置(ir_drillconfig)
			List<IRDrillConfig>  irdList = new ArrayList<IRDrillConfig>();
			int drillcount =  ServletRequestUtils.getIntParameter(request, "drillcount", 0);
			for(int i = 1 ; i <= drillcount ; i++){
					String requestName = "drillInfo"+i;
					String[] drillInfos = ServletRequestUtils.getStringParameters(request, requestName);
					if(drillInfos.length == 0){
						continue;
					}
					IRDrillConfig  vo  = new IRDrillConfig();
					vo.setDrillname(drillInfos[0]);
					vo.setReplayname(drillInfos[1]);
					irdList.add(vo);
			}
			//查询指标配置
			List<IRColumns>  colList = new ArrayList<IRColumns>();
			int colcount =  ServletRequestUtils.getIntParameter(request, "colcount", 0);
			for(int i = 1 ; i <= colcount ; i++){
					String requestName = "colinfo"+i;
					String[] colinfos = ServletRequestUtils.getStringParameters(request, requestName);
					if(colinfos.length == 0){
						continue;
					}
					IRColumns vo = new IRColumns();
					vo.setEname(colinfos[0]);
					vo.setCname(colinfos[1]);
					vo.setTabType(colinfos[2]);
//					log.info(colinfos[2]);
					vo.setSpecialInSql(colinfos[3]);
					vo.setColType(Integer.parseInt(colinfos[4]));
					vo.setIsOrderBy(Integer.parseInt(colinfos[5]));
					colList.add(vo);
			}
			
			//更新数据
			boolean result = IntReportMainService.updateEditedReport(irReport, menu, ircList, colList,irdList);
			if(!result){
				return new ContentResult("error");
			}
			//删除原模板
			String filepath =MyPathUtil.getIRPath()+menu.getId()+".html";
			File file = new File(filepath);
			if(file.exists()){
				file.delete();
			}
		}catch (Exception e) {
			e.printStackTrace();
		}
		return new ContentResult("success");
	}	
	
	
	/** 报表模板生成    模板已存在则直接render  不存在则解析生产新模板
	 *   修改 : 为处理报表编辑修改后带来的模板同步问题  将ID 由 原来的纯MENUID改为 MENUID_版本号 模式
	 * @return   
	 */
	@Path("create/{pathid}")
	@Check
	@POST
	@GET
	public ActionResult createNewReport (String pathid){
		HttpServletRequest request = beat.getRequest();
		Model model= beat.getModel();
		TemplateMethodFactory.setVelocityContext("tools", VelocityTools.class, model);
		try{
			User user = spu.getUserByCookie(request);
			String  viewPath = MyPathUtil.getIRPath()+pathid+".html";
			File file = new File(viewPath);
			if(!file.exists()){
				tp.createNewTemplate(pathid);
			}
			int menuId = Integer.parseInt(pathid.split("_")[0]);
			IRReport  irReport = iRReportService.getReportListByMenuId(menuId);
			model.add("irReport",irReport);
			
			boolean isBiz = false; //业务线类型  默认为用户产品业务线
			
			List<IRSearchConfig>  searchConfigList =   IRSearchConfigService.getListByIRid(irReport.getId());
			for(IRSearchConfig vo : searchConfigList ){
				int typeId = vo.getSearchTypeId();
				
				
				String detailValue = vo.getDetailValue();
				String showBusi = ""; //新业务线类别组件   业务线展示限定参数
				
				//参数获取
				String[] tempArrays = detailValue.split(";");
				
				switch (typeId) {
				case 11: //展现城市
					List<DisplayLocal> dlCityOneList =  new ArrayList<DisplayLocal>();
					//权限检查
					String operCitys = IntReportMainService.cityOperCheck(user);
					//全部城市权限才展示 直营&中小城市 这2个特殊选择
					if(MyStore.cityOperAll.equals(operCitys)){ 
						model.add("specity1",1);
					}
					dlCityOneList = displayLocalService.getCitysByOpers(operCitys);
					model.add("dlCityOneList",dlCityOneList);
					break;
				case 12://归属城市
					List<BelongLocal> blCityOneList =  new ArrayList<BelongLocal>();
					
					//权限检查
					String operCitysBelong = IntReportMainService.cityOperCheck(user);
					//全部城市权限才展示 直营&中小城市 这2个特殊选择
					if(MyStore.cityOperAll.equals(operCitysBelong)){ 
						model.add("specity1",1);
					}
					blCityOneList = belongLocalService.getCitysByOpers(operCitysBelong);
					
					model.add("blCityOneList",blCityOneList);
					break;
				case 17: //展现类别
					for (String tempArr : tempArrays) {
						if(tempArr.contains("show")){ //报表配置业务线展现限定  - like : show:huangye,ershou
							showBusi = tempArr.split(":")[1];
						}
						if(tempArr.contains("isBiz") && "1".equals(tempArr.split(":")[1].trim())){ //业务线类型   - like : isBiz:1      1=商业业务线  0 = 用户业务线
							isBiz = true;
						}
					}
					//用户操作权限 - 业务线判定
					String dispCheckResult = IntReportMainService.businessOperCheck(user, showBusi);
					if("error".equals(dispCheckResult)){
						return new ContentResult("No business type permission option.");
					}else{
						showBusi = dispCheckResult;
					}
					
					List<NewDisplayCate> dpBusinessTypeList = newDisplayCateService.getAllBusinessType(showBusi,isBiz);
					model.add("dpBusinessTypeList",dpBusinessTypeList);
					
					List<NewDisplayCate> dpNewCateOneList = new ArrayList<NewDisplayCate>();
					if(dpBusinessTypeList.size() == 1){ //业务线只限定展示1个的时候 同时直接将一级类别查询展示
						dpNewCateOneList =   newDisplayCateService.getLevelOne(dpBusinessTypeList.get(0).getBusiness_type(),isBiz);
					}else if(vo.getSename().contains("null")){//当报表无业务线字段时  不展示业务线控件  默认将所有一级类别展现
						dpNewCateOneList =  newDisplayCateService.getAllLevelOne();
					}
					model.add("dpNewCateOneList",dpNewCateOneList);
					model.add("isBiz",isBiz);
					break;
				case 18: //归属类别
					for (String tempArr : tempArrays) { //报表配置业务线展现限定  - like : show:huangye,ershou
						if(tempArr.contains("show")){
							showBusi = tempArr.split(":")[1];
						}
						if(tempArr.contains("isBiz") && "1".equals(tempArr.split(":")[1].trim())){ //业务线类型   - like : isBiz:1      1=商业业务线  0 = 用户业务线
							isBiz = true;
						}
					}
					
					//用户操作权限 - 业务线判定
					String belongCheckResult = IntReportMainService.businessOperCheck(user, showBusi);
					if("error".equals(belongCheckResult)){
						return new ContentResult("No business type permission option.");
					}else{
						showBusi = belongCheckResult;
					}
					
					List<NewBelongCate> bcBusinessTypeList = newBelongCateService.getAllBusinessType(showBusi,isBiz);
					model.add("bcBusinessTypeList",bcBusinessTypeList);
					
					List<NewBelongCate> bcNewCateOneList = new ArrayList<NewBelongCate>();
					if(bcBusinessTypeList.size() == 1){ //业务线只限定展示1个的时候 同时直接将一级类别查询展示
						bcNewCateOneList =   newBelongCateService.getLevelOne(bcBusinessTypeList.get(0).getBusiness_type(),isBiz);
					}else if(vo.getSename().contains("null")){//当报表无业务线字段时  不展示业务线控件  默认将所有一级类别展现
						bcNewCateOneList = newBelongCateService.getAllLevelOne();
					}
					
					model.add("bcNewCateOneList",bcNewCateOneList);
					model.add("isBiz",isBiz);
					break;
				case 19://58信息来源组件
					List<InfoSourcePlatform> infoPlatformList = infoSourcePlatformService.getAllPlatform();
					model.add("infoPlatformList",infoPlatformList);
					break;
				case 20://58流量来源组件
					String platform = "";
					if(detailValue.contains("platform")){ //like :  platform:PC/M
						for (String tempArr : tempArrays) {
							if(tempArr.contains("platform")){
								platform = tempArr.split(":")[1];
							}
						}
					}
					List<NetFlowSource> flowSourceOneList = netFlowSourceService.getSource1List(platform);
					List<NetFlowSource> finalFlowSourceOneList = new ArrayList<NetFlowSource>(); //最终展现一级来源列表
					if(MyStore.admin.equals(user.getFunction())){ //管理员权限
						finalFlowSourceOneList = flowSourceOneList;
					}else{
						//流量来源一级类权限控制处理
						Map<String,NetFlowSource> flowSourceOneMap = new HashMap<String, NetFlowSource>();
						for (NetFlowSource netFlowSource : flowSourceOneList) {
							flowSourceOneMap.put(netFlowSource.getSource1(), netFlowSource);
						}
						
						HashSet<Long> userOpersSet = userOperService.getUserOpers(user.getId());//用户全部细粒度权限
						List<OperMenu> operList = userOperService.getOperListByCate("流量数据统计", "流量来源一级渠道"); //该系列所有正常数据权限
						
						for (OperMenu operMenu : operList) {
							long operid = operMenu.getId();
							String operName = operMenu.getName();
							if(userOpersSet.contains(operid)){
								if(operid == 9){ //所有一级来源
									finalFlowSourceOneList = flowSourceOneList;
									break;
								}else{
									if(flowSourceOneMap.containsKey(operName)){
										finalFlowSourceOneList.add(flowSourceOneMap.get(operName));
									}
								}
							}
						}
					}
					model.add("flowSourceOneList",finalFlowSourceOneList);
					break;
					
				case 21://驾校一点通来源组件
					String jxedtPlatform = "";
					if(detailValue.contains("platform")){ //like :  platform:PC/M
						for (String tempArr : tempArrays) {
							if(tempArr.contains("platform")){
								jxedtPlatform = tempArr.split(":")[1];
							}
						}
					}
					List<JxedtFlowSource> jxedtSourceOneList = jxedtFlowSourceService.getSource1List(jxedtPlatform);
					model.add("jxedtSourceOneList",jxedtSourceOneList);
					break;
					
				case 22://中华英才流量来源组件
					String chrPlatform = "";
					if(detailValue.contains("platform")){ //like :  platform:PC/M
						for (String tempArr : tempArrays) {
							if(tempArr.contains("platform")){
								chrPlatform = tempArr.split(":")[1];
							}
						}
					}
					List<ChinahrSource> chrSourceOneList = chinahrSourceService.getSource1(chrPlatform);
					model.add("chrSourceOneList",chrSourceOneList);
					break;
					
				case 23://中华英才行业级联组件
					List<ChinahrIndustry> chrIndustryOneList = chinahrIndustryService.getAllCate1();
					model.add("chrIndustryOneList",chrIndustryOneList);
					break;
					
				case 24://中华英才职位级联组件
					List<ChinahrJob> chrJobOneList = chinahrJobService.getAllCate1();
					model.add("chrJobOneList",chrJobOneList);
					break;
				}
				
			}
		}catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		model.add("hasComp","");
		return  ActionResult.view("intreport/"+pathid);
	}	
	
	
	/** 通用查询
	 * @return
	 */
	@Path("search/{pathid}")
	@Check("irsearch")
	@POST
	@GET
	public ActionResult searchReport (String pathid){
		HttpServletRequest request = beat.getRequest();
		HttpServletResponse response = beat.getResponse();
		Model model= beat.getModel();
		TemplateMethodFactory.setVelocityContext("tools", VelocityTools.class, model);
		int id = Integer.parseInt(pathid.split("_")[0]);
		String groupBy =  ServletRequestUtils.getStringParameter(request, "groupBy","");//查询维度
		if(("1:all").equals(groupBy.trim()))
			groupBy="";
//		log.info(beat.getClient().getRelativeUrl());
		try{
			User user = spu.getUserByCookie(request);
			//检查模板
			String  viewPath = MyPathUtil.getIRPath()+pathid+".html";
			File file = new File(viewPath);
			if(!file.exists()){
				tp.createNewTemplate(pathid);
			}
			
			IRReport  irReport = iRReportService.getReportListByMenuId(id);
				
			
			List<IRSearchConfig>  searchConfigList =   IRSearchConfigService.getListByIRid(irReport.getId());
			
			StringBuffer url =new StringBuffer();//分页的URL
			StringBuffer  condition = new StringBuffer();//查询where条件
			StringBuilder inCondition=new StringBuilder(); //同环比条件
			StringBuffer specialValues  = new StringBuffer();//装载特殊字段  如跨表查询的起始日期 采用K:V结构 每一类以分号 ; 隔开
			HashMap<String,String>  gbMap = new HashMap<String, String>(); //分组维度的中英文对照	
			
			//添加钻取信息
			List<IRDrillConfig> drillConfiglist=IRDrillConfigService.getListByIRid(irReport.getId());
			HashMap<String, String> drillMap=new HashMap<String, String>();
			
			List<String> drills=new ArrayList<String>();
			if(drillConfiglist!=null&&drillConfiglist.size()>0)//
			{
				for(int i=0;i<drillConfiglist.size();i++)
				{
					drillMap.put(drillConfiglist.get(i).getDrillname(), drillConfiglist.get(i).getReplayname());
				}
				for(int i=0;i<drillConfiglist.size();i++)
				{
					if(checkGBContains(groupBy, drillConfiglist.get(i).getDrillname()))
					    {
						   drills.add(drillConfiglist.get(i).getDrillname());
						}
				}
				for(int i=0;i<drillConfiglist.size();i++)//如果group中包含下一级的钻取字段，则不允许本字段钻取
				{
					/*String tempdrillreplay=drillConfiglist.get(i).getReplayname();*/
					if(drills.contains(drillConfiglist.get(i).getDrillname())&&checkGBDrill(drillConfiglist.get(i).getDrillname(), groupBy, drillMap))
					{
						drills.remove(drillConfiglist.get(i).getDrillname());
					}
				}
			}		
			
			for(IRSearchConfig vo : searchConfigList ){
				int typeId = vo.getSearchTypeId();   //查询类型编号
				String sename = vo.getSename() ; //查询绑定字段
				switch (typeId) {
				case 3: //时间段
					String startDate = ServletRequestUtils.getStringParameter(request, "startDate","");
					String endDate = ServletRequestUtils.getStringParameter(request, "endDate","");
					String dateselect = ServletRequestUtils.getStringParameter(request, "dateselect","");
					condition.append(" and "+sename+">='"+startDate+"' ");
					url.append("&startDate="+startDate);
					url.append("&dateselect="+dateselect);
					condition.append(" and "+sename+"<='"+endDate+"' ");
					url.append("&endDate="+endDate);
					model.add("startDate",startDate);
					model.add("endDate",endDate);
					model.add("dateselect",dateselect);
					
					specialValues.append("startDate:"+startDate+";");
					specialValues.append("endDate:"+endDate+";");
					specialValues.append("dateName:"+sename+";");
					break;
				case 4: //时间点
					String searchDate = ServletRequestUtils.getStringParameter(request, "searchDate","");
					condition.append(" and "+sename+">='"+searchDate+"' ");
					url.append("&searchDate="+searchDate);
					model.add("searchDate",searchDate);
					break;
				case 5: //单字段模糊查询
					if(id==354&&groupBy.contains("business_type"))//渠道app特殊处理
					{
						break;
					}
					String mhValue = ServletRequestUtils.getStringParameter(request,sename ,"");
					if(!"".equals(mhValue)){
						condition.append(" and "+sename+" like '%"+mhValue+"%' ");
						inCondition.append(" and "+sename+" like '%"+mhValue+"%' ");
						url.append("&"+sename+"="+mhValue);
					}else{//为空时  判定是否为向上汇总型报表  是,则特殊处理： 查询维度包含该字段时   != 'all'  不包含  = 'all'  
						String xlDetail = vo.getDetailValue();
						if(xlDetail.contains("|all")){ //判定是否为向上汇总型报表
							String tpValue = "";
							
							if(checkGBContains(groupBy,sename)){
								tpValue = " != 'all' ";
							}else{
								tpValue = " = 'all' ";
							}
							condition.append(" and "+sename+ tpValue );
							inCondition.append(" and "+sename + tpValue );
						}
						
					}
					model.add(sename,mhValue);
					break;
				case 6://单字段精准查询
					String jzValue = ServletRequestUtils.getStringParameter(request,sename ,"");
					if(!"".equals(jzValue)){
						condition.append(" and "+sename+" = '"+jzValue+"' ");
						inCondition.append(" and "+sename+" = '"+jzValue+"' ");
						url.append("&"+sename+"="+jzValue);
					}else{//为空时  判定是否为向上汇总型报表  是,则特殊处理： 查询维度包含该字段时   != 'all'  不包含  = 'all'  
						String xlDetail = vo.getDetailValue();
						if(xlDetail.contains("|all")){ //判定是否为向上汇总型报表
							String tpValue = "";
							if(checkGBContains(groupBy,sename)){
								tpValue = " != 'all' ";
							}else{
								tpValue = " = 'all' ";
							}
							condition.append(" and "+sename+ tpValue );
							inCondition.append(" and "+sename + tpValue );
						}
						
					}
					
					model.add(sename,jzValue);
					break;
				case 7://单字段下拉框
					String xlValue = ServletRequestUtils.getStringParameter(request,sename ,"");
					
					if(!"".equals(xlValue)){
						condition.append(" and "+sename+" in( "+xlValue+") ");
						inCondition.append(" and "+sename+" in( "+xlValue+") ");
						
					}else{ //为空时  判定是否为向上汇总型报表  是,则特殊处理： 查询维度包含该字段时   != 'all'  不包含  = 'all'  
						String xlDetail = vo.getDetailValue();
						if(xlDetail.contains("|all")){ //判定是否为向上汇总型报表
							String tpValue = "";
							if(checkGBContains(groupBy,sename)){
								tpValue = " != 'all' ";
							}else{
								tpValue = " = 'all' ";
							}
							condition.append(" and "+sename+ tpValue );
							inCondition.append(" and "+sename + tpValue );
						}
					}
					
					
					model.add(sename,xlValue);
					url.append("&"+sename+"="+xlValue);
					
					break;
				case 8://分组维度	
					String gbDic = vo.getDetailValue();//groupby的中英文对照
					for(String dic : gbDic.split(";")){
						String ename = dic.split(":")[0];
						String cname = dic.split(":")[1];
						gbMap.put(ename, cname);
					}
					break;
				case 11://展现城市级联（3级）
					int dlShowLevel = 0; //级联层数
					int dlShowType = 0; //查询类型  1：正常   2：兼容老的向上汇总报表(后期去除)   3.新的向上汇总
					for(String temp : vo.getDetailValue().split(";")){
						if(temp.split(":")[0].equals("level")){
							dlShowLevel = Integer.parseInt(temp.split(":")[1]);
						}else if(temp.split(":")[0].equals("type")){
							dlShowType = Integer.parseInt(temp.split(":")[1]);
						}
					}
					
					String[] dlEnames = sename.split(";"); //绑定字段集
					
					//一级城市
					String dlCity1 = ServletRequestUtils.getStringParameter(request,"dlCityOne" ,"");
					
					List<DisplayLocal> dlCityOneList =  new ArrayList<DisplayLocal>();
					//权限检查
					String operCitys = IntReportMainService.cityOperCheck(user);
					//全部城市权限才展示 直营&中小城市 这2个特殊选择
					if(MyStore.cityOperAll.equals(operCitys)){ 
						model.add("specity1",1);
					}
					dlCityOneList = displayLocalService.getCitysByOpers(operCitys);
					
					//城市未选&&权限非全部城市   则 需要根据权限进行限定条件
					if("".equals(dlCity1) && !MyStore.cityOperAll.equals(operCitys)){
						if(MyStore.cityOperZY.equals(operCitys)){ //直营
							dlCity1 = MyStore.zycitys;
						}else if(MyStore.cityOperQD.equals(operCitys)){//渠道
							dlCity1 = MyStore.cityOperQD; //渠道比较特殊  先赋予一个值 后面查询条件用not in作特殊处理
						}else { //其他
							dlCity1 = operCitys.substring(0,operCitys.lastIndexOf(","));
						}
						
					}
					
					model.add("dlCityOneList",dlCityOneList);
					//全部渠道城市选择特殊处理  
					if(MyStore.cityOperQD.equals(dlCity1)){
						url.append("&dlCityOne="+"");
						model.add("dlCityOne","");
					}else{
						url.append("&dlCityOne="+dlCity1);
						model.add("dlCityOne",dlCity1);
					}
					
					//不为空则直接写入条件 ;为空则根据汇总方式进行条件判定  后面每一级都如此
					if(!"".equals(dlCity1)){ //非空
						//全部渠道城市选择特殊处理  
						if(MyStore.cityOperQD.equals(dlCity1)){
							//渠道城市  =  非直营城市  &&　不等于all(处理向上汇总型报表)
							String dlCity1Deal = " not in("+MyStore.zycitys+") and "+dlEnames[0]+" !='all' " ;
							condition.append(" and "+dlEnames[0] + dlCity1Deal);
							inCondition.append(" and "+dlEnames[0] + dlCity1Deal);
						}else{
							String dlCity1Deal = " in("+dlCity1+") " ;
							condition.append(" and "+dlEnames[0] + dlCity1Deal);
							inCondition.append(" and "+dlEnames[0] + dlCity1Deal);
						}
					}else{
						if(dlShowType == 3){ // 向上汇总报表
							/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
							boolean checkGB = false;
							for(int i = 0 ; i < dlEnames.length; i ++){
								String check = dlEnames[i];
								if(groupBy.contains(check)){
									checkGB = true;
									break;
								}
							}
							String dlCity1Deal = "";
							if(checkGB){
								dlCity1Deal = " != 'all' ";
							}else{
								dlCity1Deal = " = 'all' ";
							}
							condition.append(" and "+dlEnames[0] + dlCity1Deal);
							inCondition.append(" and "+dlEnames[0] + dlCity1Deal);
						}
					}
				
					if(MyStore.cityOperQD.equals(dlCity1)){
						dlCity1 = ""; //渠道城市 city1条件使用完了 要改回正常状态 否则影响后续使用
					}
					
					//二级城市
					String dlCity2 = ServletRequestUtils.getStringParameter(request,"dlCityTwo" ,"");
					if(dlShowLevel >= 2){
						url.append("&dlCityTwo="+dlCity2);
						model.add("dlCityTwo",dlCity2);
						if(!"".equals(dlCity1) && dlCity1.split(",").length == 1 ){
							List<DisplayLocal> dlCityTwoList = displayLocalService.getLevelTwo(StringUtils.strip(dlCity1, "' "));
							model.add("dlCityTwoList",dlCityTwoList);
						}
						
						if(!"".equals(dlCity2)){ //非空
							String dlCity2Deal = " in("+dlCity2+") " ; 
							condition.append(" and "+dlEnames[1] + dlCity2Deal);
							inCondition.append(" and "+dlEnames[1] + dlCity2Deal);
						}else{
							if(dlShowType == 2){ 
								String dlCity2Deal = "" ;
								if(groupBy.contains(dlEnames[1])){
									dlCity2Deal = " is not null ";
								}else{
									dlCity2Deal = " is null ";
								}
								condition.append(" and "+dlEnames[1] + dlCity2Deal);
								inCondition.append(" and "+dlEnames[1] + dlCity2Deal);
							}else if(dlShowType == 3){ // 向上汇总报表   
								/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
								boolean checkGB = false;
								for(int i = 1 ; i < dlEnames.length; i ++){
									String check = dlEnames[i];
									if(groupBy.contains(check)){
										checkGB = true;
										break;
									}
								}
								String dlCity2Deal = "" ;
								if(checkGB){
									dlCity2Deal = " != 'all' ";
								}else{
									dlCity2Deal = " = 'all' ";
								}
								condition.append(" and "+dlEnames[1] + dlCity2Deal);
								inCondition.append(" and "+dlEnames[1] + dlCity2Deal);
							}
						}
					}
					
					if(dlShowLevel >= 3){
						String dlCity3 = ServletRequestUtils.getStringParameter(request,"dlCityThree","");
						if(!"".equals(dlCity1) && !"".equals(dlCity2) &&  dlCity2.split(",").length == 1 ){
							List<DisplayLocal> dlCityThreeList = displayLocalService.getLevelThree(StringUtils.strip(dlCity1, "' "), StringUtils.strip(dlCity2, "' "));
							model.add("dlCityThreeList",dlCityThreeList);
						}
						model.add("dlCityThree",dlCity3);
						url.append("&dlCityThree="+dlCity3);
						
						if(!"".equals(dlCity3)){ //非空
							String dlCity3Deal = " in("+dlCity3+") " ;  
							condition.append(" and "+dlEnames[2] + dlCity3Deal);
							inCondition.append(" and "+dlEnames[2] + dlCity3Deal);
						}else{
							if(dlShowType == 2){ 
								String dlCity3Deal = "" ;
								if(groupBy.contains(dlEnames[2])){
									dlCity3Deal = " is not null ";
								}else{
									dlCity3Deal = " is null ";
								}
								condition.append(" and "+dlEnames[2] + dlCity3Deal);
								inCondition.append(" and "+dlEnames[2] + dlCity3Deal);
							}else if(dlShowType == 3){ // 向上汇总报表   
								/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
								boolean checkGB = false;
								for(int i = 2 ; i < dlEnames.length; i ++){
									String check = dlEnames[i];
									if(groupBy.contains(check)){
										checkGB = true;
										break;
									}
								}
								String dlCity3Deal = "" ;
								if(checkGB){
									dlCity3Deal = " != 'all' ";
								}else{
									dlCity3Deal = " = 'all' ";
								}
								condition.append(" and "+dlEnames[2] + dlCity3Deal);
								inCondition.append(" and "+dlEnames[2] + dlCity3Deal);
							}
						
						}
						
					}
					
					//老的流量数据  写死city3 =' '   (后期去除)
					if(dlShowLevel == 2 && dlShowType == 2){
						condition.append(" and city3 is null ");
						inCondition.append(" and city3 is null ");
					}
					break;
				case 12://归属城市级联（3级）
					int blShowLevel = 0; //级联层数
					int blShowType = 0; //查询类型  1：正常   3.向上汇总报表
					for(String temp : vo.getDetailValue().split(";")){
						if(temp.split(":")[0].equals("level")){
							blShowLevel = Integer.parseInt(temp.split(":")[1]);
						}else if(temp.split(":")[0].equals("type")){
							blShowType = Integer.parseInt(temp.split(":")[1]);
						}
					}
					
					String[] blEnames = sename.split(";");
					
					//一级城市
					String blCity1 = ServletRequestUtils.getStringParameter(request,"blCityOne" ,"");
					List<BelongLocal> blCityOneList = new ArrayList<BelongLocal>();
					//权限检查
					String operCitysBelong = IntReportMainService.cityOperCheck(user);
					//全部城市权限才展示 直营&中小城市 这2个特殊选择
					if(MyStore.cityOperAll.equals(operCitysBelong)){ 
						model.add("specity1",1);
					}
					blCityOneList = belongLocalService.getCitysByOpers(operCitysBelong);
					
					//城市未选&&权限非全部城市   则 需要根据权限进行限定条件
					if("".equals(blCity1) && !MyStore.cityOperAll.equals(operCitysBelong)){
						if(MyStore.cityOperZY.equals(operCitysBelong)){ //直营
							blCity1 = MyStore.zycitys;
						}else if(MyStore.cityOperQD.equals(operCitysBelong)){//渠道
							blCity1 = MyStore.cityOperQD;
						}else { //其他
							blCity1 = operCitysBelong.substring(0,operCitysBelong.lastIndexOf(","));
						}
					}
					
					
					model.add("blCityOneList",blCityOneList);
					//渠道城市特殊处理  
					if(MyStore.cityOperQD.equals(blCity1)){
						url.append("&blCityOne="+"");
						model.add("blCityOne","");
					}else{
						url.append("&blCityOne="+blCity1);
						model.add("blCityOne",blCity1);
					}
				
					
					if(!"".equals(blCity1)){ //非空
						//全部渠道城市选择特殊处理  
						if(MyStore.cityOperQD.equals(blCity1)){
							//渠道城市  =  非直营城市  &&　不等于all(处理向上汇总型报表)
							String blCity1Deal = " not in("+MyStore.zycitys+") and "+blEnames[0]+" !='all' " ;
							condition.append(" and "+blEnames[0] + blCity1Deal);
							inCondition.append(" and "+blEnames[0] + blCity1Deal);
						}else{
							String blCity1Deal =  " in("+blCity1+") " ;
							condition.append(" and "+blEnames[0] + blCity1Deal);
							inCondition.append(" and "+blEnames[0] + blCity1Deal);
						}
					}else{
						if(blShowType == 3){ // 向上汇总报表   
							/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
							boolean checkGB = false;
							for(int i = 0 ; i < blEnames.length; i ++){
								String check = blEnames[i];
								if(groupBy.contains(check)){
									checkGB = true;
									break;
								}
							}
							String blCity1Deal = "";
							if(checkGB){
								blCity1Deal = " != 'all' ";
							}else{
								blCity1Deal = " = 'all' ";
							}
							condition.append(" and "+blEnames[0] + blCity1Deal);
							inCondition.append(" and "+blEnames[0] + blCity1Deal);
						}
					}
					
					if(MyStore.cityOperQD.equals(blCity1)){
						blCity1 = ""; //渠道城市 city1条件使用完了 要改回正常状态 否则影响后续使用
					}
					
					//二级城市
					String blCity2 = ServletRequestUtils.getStringParameter(request,"blCityTwo" ,"");
					if(blShowLevel >= 2){
						url.append("&blCityTwo="+blCity2);
						model.add("blCityTwo",blCity2);
						if(!"".equals(blCity1) && blCity1.split(",").length == 1 ){
							List<BelongLocal> blCityTwoList = belongLocalService.getLevelTwo(StringUtils.strip(blCity1, "' "));
							model.add("blCityTwoList",blCityTwoList);
						}
						if(!"".equals(blCity2)){ //非空
							String blCity2Deal = " in("+blCity2+") " ;  
							condition.append(" and "+blEnames[1] + blCity2Deal);
							inCondition.append(" and "+blEnames[1] + blCity2Deal);
						}else{
							if( blShowType == 3){ // 向上汇总报表   
								/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
								boolean checkGB = false;
								for(int i = 1 ; i < blEnames.length; i ++){
									String check = blEnames[i];
									if(groupBy.contains(check)){
										checkGB = true;
										break;
									}
								}
								String blCity2Deal = "";
								if(checkGB){
									blCity2Deal = " != 'all' ";
								}else{
									blCity2Deal = " = 'all' ";
								}
								condition.append(" and "+blEnames[1] + blCity2Deal);
								inCondition.append(" and "+blEnames[1] + blCity2Deal);
							}
						}
												
					}
					
					if(blShowLevel >= 3){
						String blCity3 = ServletRequestUtils.getStringParameter(request,"blCityThree","");
						url.append("&blCityThree="+blCity3);
						model.add("blCityThree",blCity3);
						if(!"".equals(blCity1)  && !"".equals(blCity2) && blCity2.split(",").length == 1 ){
							List<BelongLocal> blCityThreeList = belongLocalService.getLevelThree(StringUtils.strip(blCity1, "' "), StringUtils.strip(blCity2, "' "));
							model.add("blCityThreeList",blCityThreeList);
						}
						
						if(!"".equals(blCity3)){ //非空
							String blCity3Deal = " in("+blCity3+") " ;  
							condition.append(" and "+blEnames[2] + blCity3Deal);
							inCondition.append(" and "+blEnames[2] + blCity3Deal);
						}else{
							if( blShowType == 3){ // 向上汇总报表   
								/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
								boolean checkGB = false;
								for(int i = 2 ; i < blEnames.length; i ++){
									String check = blEnames[i];
									if(groupBy.contains(check)){
										checkGB = true;
										break;
									}
								}
								String blCity3Deal = "";
								if(checkGB){
									blCity3Deal = " != 'all' ";
								}else{
									blCity3Deal = " = 'all' ";
								}
								condition.append(" and "+blEnames[2] + blCity3Deal);
								inCondition.append(" and "+blEnames[2] + blCity3Deal);
							}
						}
					}
					break;
				case 13://图表绘制
					String chartDetail = vo.getDetailValue();
					String comparGB = "";
					//去掉维度中的数字标记
					if(!"".equals(groupBy)){
						for(String temp : groupBy.split(",")){ 
							comparGB = comparGB+temp.split(":")[1]+",";
						}
						comparGB = comparGB.substring(0,comparGB.lastIndexOf(","));
					}
					if(chartDetail.contains("all")){  //无论查询维度是什么  都只有一种图表
						int chartType  = Integer.parseInt(chartDetail.split(":")[1]);
						if(chartType == 1){
							model.add("hasgraph",1);//曲线图
						}else if(chartType == 2){
							model.add("haspie",1);//饼图
						}
					}else{
						String[] details = chartDetail.split(";");
						for(String detail : details){
							String gb = detail.split(":")[0];
							int chartType = Integer.parseInt(detail.split(":")[1]);
							if(gb.equals(comparGB)){
								if(chartType == 1){
									model.add("hasgraph",1);
								}else if(chartType == 2){
									model.add("haspie",1);
								}
							}
						}
					}
					model.add("hasgraph",1);
					break;
				case 17://展现品类组件（新）- 只到3级
					int newShowLevel = 0; //级联层数
					int newShowType = 0; //查询类型  1：正常   3：向上汇总
					String showBusi = "";//展示业务线限定参数  无限定则默认为空 = 全部展示
					boolean isBiz = false; // 业务线类型   1=商业业务线  0 = 用户业务线
					
					for(String temp : vo.getDetailValue().split(";")){
						if(temp.split(":")[0].equals("level")){
							newShowLevel = Integer.parseInt(temp.split(":")[1]);
						}else if(temp.split(":")[0].equals("type")){
							newShowType = Integer.parseInt(temp.split(":")[1]);
						}else if(temp.split(":")[0].equals("show")){
							showBusi = temp.split(":")[1];
						}else if(temp.split(":")[0].equals("isBiz") && "1".equals(temp.split(":")[1].trim())){ //业务线类型   - like : isBiz:1      1=商业业务线  0 = 用户业务线
							isBiz = true;
						}
					}
					
					model.add("isBiz", isBiz);
					
					String[] newEnames = sename.split(";");

					//用户操作权限 - 业务线判定
					String dispCheckResult = IntReportMainService.businessOperCheck(user, showBusi);
					if("error".equals(dispCheckResult)){
						return new ContentResult("No business type permission option.");
					}else{
						showBusi = dispCheckResult;
					}
					
					//频道
					String dpBusinessTypeName = ServletRequestUtils.getStringParameter(request,"dpBusinessTypeName" ,"");
					if("".equals(dpBusinessTypeName) && !"".equals(showBusi)){
						for (String temp : showBusi.split(",")) {
							dpBusinessTypeName = dpBusinessTypeName + "'" + temp+"',";
						}
						dpBusinessTypeName = dpBusinessTypeName.substring(0,dpBusinessTypeName.lastIndexOf(","));
					}
					url.append("&dpBusinessTypeName="+dpBusinessTypeName);
					model.add("dpBusinessTypeName",dpBusinessTypeName);
					
					List<NewDisplayCate> dpBusinessTypeList = newDisplayCateService.getAllBusinessType(showBusi , isBiz);//业务线列表
					model.add("dpBusinessTypeList",dpBusinessTypeList);
					
					if(!"null".equals(newEnames[0].toLowerCase())){ // 表内有业务线字段的
						if(!"".equals(dpBusinessTypeName)){ //无论哪种newShowType   有值则写入条件
							condition.append(" and "+newEnames[0]+" in("+dpBusinessTypeName+") ");
							inCondition.append(" and "+newEnames[0]+" in("+dpBusinessTypeName+") ");
						}else if("".equals(dpBusinessTypeName) && newShowType == 3){ // 向上汇总报表   
							/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
							boolean checkGB = false;
							for(int i = 0 ; i < newEnames.length; i ++){
								String check = newEnames[i];
								if(groupBy.contains(check)){
									checkGB = true;
									break;
								}
							}
	  						String dpBusinessTypeNameDeal = dpBusinessTypeName;
							if(checkGB){
								dpBusinessTypeNameDeal = " != 'all' ";
							}else{
								dpBusinessTypeNameDeal = " = 'all' ";
							}
							condition.append(" and "+newEnames[0] + dpBusinessTypeNameDeal);
							inCondition.append(" and "+newEnames[0] + dpBusinessTypeNameDeal);
						}
					}else{// 没有业务线字段的
						dpBusinessTypeName="";
					}
					
					
					
					//一级品类
					String dpNewCateOne = ServletRequestUtils.getStringParameter(request,"dpNewCateOne" ,"");
					url.append("&dpNewCateOne="+dpNewCateOne);
					model.add("dpNewCateOne",dpNewCateOne);
					
					List<NewDisplayCate> dpNewCateOneList = new ArrayList<NewDisplayCate>();
					
					
					if("null".equals(newEnames[0].toLowerCase())){ // 表内无业务线字段的  把一级类全部拿出来
						dpNewCateOneList = newDisplayCateService.getAllLevelOne();
					}else if(!"".equals(dpBusinessTypeName) && dpBusinessTypeName.split(",").length == 1){
						dpNewCateOneList = newDisplayCateService.getLevelOne(StringUtils.strip(dpBusinessTypeName, "' "), isBiz);//根据业务线获取对应一级类
					}
					
					model.add("dpNewCateOneList",dpNewCateOneList);
					
					if(!"".equals(dpNewCateOne)){
						condition.append(" and "+newEnames[1]+" in("+dpNewCateOne+") ");
						inCondition.append(" and "+newEnames[1]+" in("+dpNewCateOne+") ");
					}else if("".equals(dpNewCateOne)){ 
						if(newShowType == 3){// 向上汇总报表   
							/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
							boolean checkGB = false;
							for(int i = 1 ; i < newEnames.length; i ++){
								String check = newEnames[i];
								if(groupBy.contains(check)){
									checkGB = true;
									break;
								}
							}
	  						String dpNewCateOneDeal = dpNewCateOne;
							if(checkGB){
								dpNewCateOneDeal = " != 'all' ";
							}else{
								dpNewCateOneDeal = " = 'all' ";
							}
							condition.append(" and "+newEnames[1]+ dpNewCateOneDeal);
							inCondition.append(" and "+newEnames[1]+ dpNewCateOneDeal);
						}
					}
					
					//二级品类
					String dpNewCateTwo = ServletRequestUtils.getStringParameter(request,"dpNewCateTwo" ,"");
					if(newShowLevel >= 2){
						url.append("&dpNewCateTwo="+dpNewCateTwo);
						model.add("dpNewCateTwo",dpNewCateTwo);
						List<NewDisplayCate> dpNewCateTwoList = new ArrayList<NewDisplayCate>();
						if(!"".equals(dpNewCateOne) && dpNewCateOne.split(",").length == 1){
							dpNewCateTwoList = newDisplayCateService.getLevelTwo(StringUtils.strip(dpBusinessTypeName, "' "),StringUtils.strip(dpNewCateOne, "' "), isBiz);
							model.add("dpNewCateTwoList",dpNewCateTwoList);
						}
						
						if(!"".equals(dpNewCateTwo) ){
							condition.append(" and "+newEnames[2]+" in("+dpNewCateTwo+") ");
							inCondition.append(" and "+newEnames[2]+" in("+dpNewCateTwo+") ");
						}else if("".equals(dpNewCateTwo) ){ 
							if(newShowType == 3){// 向上汇总报表  
								/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
								boolean checkGB = false;
								for(int i = 2 ; i < newEnames.length; i ++){
									String check = newEnames[i];
									if(groupBy.contains(check)){
										checkGB = true;
										break;
									}
								}
		  						String dpNewCateTwoDeal = dpNewCateTwo;
								if(checkGB){
									dpNewCateTwoDeal = " != 'all' ";
								}else{
									dpNewCateTwoDeal = " = 'all' ";
								}
								condition.append(" and "+newEnames[2] + dpNewCateTwoDeal);
								inCondition.append(" and "+newEnames[2] + dpNewCateTwoDeal);
							}
						}
					}
					//三级品类
					if(newShowLevel >= 3){
						String dpNewCateThree = ServletRequestUtils.getStringParameter(request,"dpNewCateThree","");
						url.append("&dpNewCateThree="+dpNewCateThree);
						model.add("dpNewCateThree",dpNewCateThree);
						if( !"".equals(dpNewCateTwo) && dpNewCateOne.split(",").length == 1 && dpNewCateTwo.split(",").length == 1){
							List<NewDisplayCate> dpNewCateThreeList = newDisplayCateService.getLevelThree(StringUtils.strip(dpBusinessTypeName, "' "),StringUtils.strip(dpNewCateOne, "' "),StringUtils.strip(dpNewCateTwo, "' "), isBiz);
							model.add("dpNewCateThreeList",dpNewCateThreeList);
						}
					
						if(!"".equals(dpNewCateThree) ){
							condition.append(" and "+newEnames[3]+" in("+dpNewCateThree+") ");
							inCondition.append(" and "+newEnames[3]+" in("+dpNewCateThree+") ");
						}else if("".equals(dpNewCateThree) && newShowType == 3){ // 向上汇总报表   
							/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
							//检查查询维度是否包含本级或任意次级
							boolean checkGB = false;
							for(int i = 3 ; i < newEnames.length; i ++){
								String check = newEnames[i];
								if(groupBy.contains(check)){
									checkGB = true;
									break;
								}
							}
	  						String dpNewCateThreeDeal = dpNewCateThree;
							if(checkGB){
								dpNewCateThreeDeal = " != 'all' ";
							}else{
								dpNewCateThreeDeal = " = 'all' ";
							}
							condition.append(" and "+newEnames[3] + dpNewCateThreeDeal);
							inCondition.append(" and "+newEnames[3] + dpNewCateThreeDeal);
						}
					}
					break;
					
				case 18://归属品类组件（新）- 只到3级
					int newBcLevel = 0; //级联层数
					int newBcType = 0; //查询类型  1：正常   3：向上汇总
					String newBcshowBuis = "";//展示业务线限定参数  无限定则默认为空 = 全部展示
					boolean bciIsBiz = false;
					for(String temp : vo.getDetailValue().split(";")){
						if(temp.split(":")[0].equals("level")){
							newBcLevel = Integer.parseInt(temp.split(":")[1]);
						}else if(temp.split(":")[0].equals("type")){
							newBcType = Integer.parseInt(temp.split(":")[1]);
						}else if(temp.split(":")[0].equals("show")){
							newBcshowBuis = temp.split(":")[1];
						}else if(temp.split(":")[0].equals("isBiz") && "1".equals(temp.split(":")[1].trim())){ //业务线类型   - like : isBiz:1      1=商业业务线  0 = 用户业务线
							bciIsBiz = true;
						}
					}
					String[] newBcEnames = sename.split(";");
					model.add("isBiz",bciIsBiz);
					
					//频道
					//用户操作权限 - 业务线判定
					String belongCheckResult = IntReportMainService.businessOperCheck(user, newBcshowBuis);
					if("error".equals(belongCheckResult)){
						return new ContentResult("No business type permission option.");
					}else{
						newBcshowBuis = belongCheckResult;
					}
					
					//频道
					String bcBusinessTypeName = ServletRequestUtils.getStringParameter(request,"bcBusinessTypeName" ,"");
					if("".equals(bcBusinessTypeName) && !"".equals(newBcshowBuis)){
						for (String temp : newBcshowBuis.split(",")) {
							bcBusinessTypeName = bcBusinessTypeName + "'" + temp+"',";
						}
						bcBusinessTypeName = bcBusinessTypeName.substring(0,bcBusinessTypeName.lastIndexOf(","));
					}
					
					
					url.append("&bcBusinessTypeName="+bcBusinessTypeName);
					model.add("bcBusinessTypeName",bcBusinessTypeName);
					
					List<NewBelongCate> bcBusinessTypeList = newBelongCateService.getAllBusinessType(newBcshowBuis,bciIsBiz);//业务线列表
					model.add("bcBusinessTypeList",bcBusinessTypeList);
					
					
					if(!"null".equals(newBcEnames[0].toLowerCase())){ // 表内有业务线字段的
						if(!"".equals(bcBusinessTypeName)){
							condition.append(" and "+newBcEnames[0]+" in("+bcBusinessTypeName+") ");
							inCondition.append(" and "+newBcEnames[0]+" in("+bcBusinessTypeName+") ");
						}else if("".equals(bcBusinessTypeName) && newBcType == 3){ // 向上汇总报表   
							/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
							//检查查询维度是否包含本级或任意次级
							boolean checkGB = false;
							for(int i = 0 ; i < newBcEnames.length; i ++){
								String check = newBcEnames[i];
								if(groupBy.contains(check)){
									checkGB = true;
									break;
								}
							}
	  						String bcBusinessTypeNameDeal = bcBusinessTypeName;
							if(checkGB){
								bcBusinessTypeNameDeal = " != 'all' ";
							}else{
								bcBusinessTypeNameDeal = " = 'all' ";
							}
							condition.append(" and "+newBcEnames[0] + bcBusinessTypeNameDeal);
							inCondition.append(" and "+newBcEnames[0] + bcBusinessTypeNameDeal);
						}
					}else{		// 没有业务线字段的
						bcBusinessTypeName="";
					}
					//一级品类
					String bcNewCateOne = ServletRequestUtils.getStringParameter(request,"bcNewCateOne" ,"");
					List<NewBelongCate> bcNewCateOneList = new ArrayList<NewBelongCate>();
					if("null".equals(newBcEnames[0].toLowerCase())){ // 表内无业务线字段的  把一级类全部拿出来
						bcNewCateOneList = newBelongCateService.getAllLevelOne();
					}else if(!"".equals(bcBusinessTypeName) && bcBusinessTypeName.split(",").length == 1){
						bcNewCateOneList = newBelongCateService.getLevelOne(StringUtils.strip(bcBusinessTypeName, "' "),bciIsBiz);//根据业务线获取对应一级类
					} 
					
					
					model.add("bcNewCateOneList",bcNewCateOneList);
					url.append("&bcNewCateOne="+bcNewCateOne);
					model.add("bcNewCateOne",bcNewCateOne);
					if(!"".equals(bcNewCateOne)){
						condition.append(" and "+newBcEnames[1]+" in("+bcNewCateOne+") ");
						inCondition.append(" and "+newBcEnames[1]+" in("+bcNewCateOne+") ");
					}else if("".equals(bcNewCateOne)){ 
						if(newBcType == 3){// 向上汇总报表   
							/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
							//检查查询维度是否包含本级或任意次级
							boolean checkGB = false;
							for(int i = 1 ; i < newBcEnames.length; i ++){
								String check = newBcEnames[i];
								if(groupBy.contains(check)){
									checkGB = true;
									break;
								}
							}
	  						String bcNewCateOneDeal = bcNewCateOne;
							if(checkGB){
								bcNewCateOneDeal = " != 'all' ";
							}else{
								bcNewCateOneDeal = " = 'all' ";
							}
							condition.append(" and "+newBcEnames[1] + bcNewCateOneDeal);
							inCondition.append(" and "+newBcEnames[1] + bcNewCateOneDeal);
						}
					}
					
					
					//二级品类
					String bcNewCateTwo = ServletRequestUtils.getStringParameter(request,"bcNewCateTwo" ,"");
					if(newBcLevel >= 2){
						url.append("&bcNewCateTwo="+bcNewCateTwo);
						model.add("bcNewCateTwo",bcNewCateTwo);
						List<NewBelongCate> bcNewCateTwoList = new ArrayList<NewBelongCate>();
						if(!"".equals(bcNewCateOne) && bcNewCateOne.split(",").length == 1){
							bcNewCateTwoList = newBelongCateService.getLevelTwo(StringUtils.strip(bcBusinessTypeName, "' "),StringUtils.strip(bcNewCateOne, "' "),bciIsBiz);
							model.add("bcNewCateTwoList",bcNewCateTwoList);
						}
						if(!"".equals(bcNewCateTwo)){
							condition.append(" and "+newBcEnames[2]+" in("+bcNewCateTwo+") ");
							inCondition.append(" and "+newBcEnames[2]+" in("+bcNewCateTwo+") ");
						}else if("".equals(bcNewCateTwo)){ 
							if(newBcType == 3){// 向上汇总报表   
								/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
								boolean checkGB = false;
								for(int i = 2 ; i < newBcEnames.length; i ++){
									String check = newBcEnames[i];
									if(groupBy.contains(check)){
										checkGB = true;
										break;
									}
								}
		  						String bcNewCateTwoDeal = bcNewCateTwo;
								if(checkGB){
									bcNewCateTwoDeal = " != 'all' ";
								}else{
									bcNewCateTwoDeal = " = 'all' ";
								}
								condition.append(" and "+newBcEnames[2] + bcNewCateTwoDeal);
								inCondition.append(" and "+newBcEnames[2] + bcNewCateTwoDeal);
							}
						}
					}
					//三级品类
					if(newBcLevel >= 3){
						String bcNewCateThree = ServletRequestUtils.getStringParameter(request,"bcNewCateThree","");
						url.append("&bcNewCateThree="+bcNewCateThree);
						model.add("bcNewCateThree",bcNewCateThree);
						if(!"".equals(bcNewCateTwo) && bcNewCateOne.split(",").length == 1 && bcNewCateTwo.split(",").length == 1){
							List<NewBelongCate> bcNewCateThreeList = newBelongCateService.getLevelThree(StringUtils.strip(bcBusinessTypeName, "' "),StringUtils.strip(bcNewCateOne, "' "),StringUtils.strip(bcNewCateTwo, "' "),bciIsBiz);
							model.add("bcNewCateThreeList",bcNewCateThreeList);
						}
						
						if(!"".equals(bcNewCateThree) ){
							condition.append(" and "+newBcEnames[3]+" in("+bcNewCateThree+") ");
							inCondition.append(" and "+newBcEnames[3]+" in("+bcNewCateThree+") ");
						}else if("".equals(bcNewCateThree) && newBcType == 3){ // 向上汇总报表   
							/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
							boolean checkGB = false;
							for(int i = 3 ; i < newBcEnames.length; i ++){
								String check = newBcEnames[i];
								if(groupBy.contains(check)){
									checkGB = true;
									break;
								}
							}
	  						String bcNewCateThreeDeal = bcNewCateThree;
							if(checkGB){
								bcNewCateThreeDeal = " != 'all' ";
							}else{
								bcNewCateThreeDeal = " = 'all' ";
							}
							condition.append(" and "+newBcEnames[3] + bcNewCateThreeDeal);
							inCondition.append(" and "+newBcEnames[3] + bcNewCateThreeDeal);
						}
						
					}
					break;
					
				case 19://信息来源级联组件  （向上汇总型）
					int infoSourceLevel = 0; //级联层数数
					for(String temp : vo.getDetailValue().split(";")){
						if(temp.split(":")[0].equals("level")){
							infoSourceLevel = Integer.parseInt(temp.split(":")[1]);
						}
					}
					String[] infoSourceEnames = sename.split(";");
					
					//平台
					String infoPlatform = ServletRequestUtils.getStringParameter(request,"infoPlatform" ,"");
					url.append("&infoPlatform="+infoPlatform);
					model.add("infoPlatform",infoPlatform);
					List<InfoSourcePlatform> infoPlatformList = infoSourcePlatformService.getAllPlatform();
					model.add("infoPlatformList",infoPlatformList);
					
					if(!"".equals(infoPlatform)){
						condition.append(" and "+infoSourceEnames[0]+" in("+infoPlatform+") ");
						inCondition.append(" and "+infoSourceEnames[0]+" in("+infoPlatform+") ");
					}else if("".equals(infoPlatform)){ 
						/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
						boolean checkGB = false;
						for(int i = 0 ; i < infoSourceEnames.length; i ++){
							String check = infoSourceEnames[i];
							if(groupBy.contains(check)){
								checkGB = true;
								break;
							}
						}
						String infoPlatformDeal = infoPlatform;
						if(checkGB){
							infoPlatformDeal = " != 'all' ";
						}else{
							infoPlatformDeal = " = 'all' ";
						}
						condition.append(" and "+infoSourceEnames[0] + infoPlatformDeal);
						inCondition.append(" and "+infoSourceEnames[0] + infoPlatformDeal);
					}
					
					//sourceName
					String infoSourceName = ServletRequestUtils.getStringParameter(request,"infoSourceName" ,"");
					if(infoSourceLevel >= 2){
						url.append("&infoSourceName="+infoSourceName);
						model.add("infoSourceName",infoSourceName);
						if(!"".equals(infoPlatform) && infoPlatform.split(",").length == 1){
							List<InfoSourcePlatform> infoSourceList = infoSourcePlatformService.getSourceList(StringUtils.strip(infoPlatform, "' "));
							model.add("infoSourceList",infoSourceList);
						}
						if(!"".equals(infoSourceName)){
							condition.append(" and "+infoSourceEnames[1]+" in("+infoSourceName+") ");
							inCondition.append(" and "+infoSourceEnames[1]+" in("+infoSourceName+") ");
						}else if("".equals(infoSourceName)){ // 向上汇总报表   
							/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
							boolean checkGB = false;
							for(int i = 1 ; i < infoSourceEnames.length; i ++){
								String check = infoSourceEnames[i];
								if(groupBy.contains(check)){
									checkGB = true;
									break;
								}
							}
	  						String infoSourceIdDeal = infoSourceName;
							if(checkGB){
								infoSourceIdDeal = " != 'all' ";
							}else{
								infoSourceIdDeal = " = 'all' ";
							}
							condition.append(" and "+infoSourceEnames[1] + infoSourceIdDeal);
							inCondition.append(" and "+infoSourceEnames[1] + infoSourceIdDeal);
						}
					}
					break;
					
					
				case 20://流量来源级联组件  （向上汇总型）
					int flowSourceLevel = 0; //级联层数数
					String flowSourcePlatform = ""; //平台类型
					for(String temp : vo.getDetailValue().split(";")){
						if(temp.split(":")[0].equals("level")){
							flowSourceLevel = Integer.parseInt(temp.split(":")[1]);
						}
						if(temp.split(":")[0].equals("platform")){
							flowSourcePlatform = temp.split(":")[1];
						}
					}
					String[] flowSourceEnames = sename.split(";");
					

					//一级来源  
					String flowSourceOne = ServletRequestUtils.getStringParameter(request,"flowSourceOne" ,"");
					
					//一级来源完整列表
					List<NetFlowSource> flowSourceOneList = netFlowSourceService.getSource1List(flowSourcePlatform);
					//一级来源展示列表
					List<NetFlowSource> finalFlowSourceOneList = new ArrayList<NetFlowSource>();
					
					if(MyStore.admin.equals(user.getFunction())){ //管理员权限
						finalFlowSourceOneList = flowSourceOneList;
					}else{
						//流量来源一级类权限控制处理
						Map<String,NetFlowSource> flowSourceOneMap = new HashMap<String, NetFlowSource>();
						for (NetFlowSource netFlowSource : flowSourceOneList) {
							flowSourceOneMap.put(netFlowSource.getSource1(), netFlowSource);
						}
						
						HashSet<Long> userOpersSet = userOperService.getUserOpers(user.getId());//用户全部细粒度权限
						List<OperMenu> operList = userOperService.getOperListByCate("流量数据统计", "流量来源一级渠道"); //该系列所有正常数据权限
						
						String checkFowSourceOne = "";
						for (OperMenu operMenu : operList) {
							long operid = operMenu.getId();
							String operName = operMenu.getName();
							if(userOpersSet.contains(operid)){
								if(operid == 9){ //所有一级来源
									finalFlowSourceOneList = flowSourceOneList;
									break;
								}else{
									if(flowSourceOneMap.containsKey(operName)){
										finalFlowSourceOneList.add(flowSourceOneMap.get(operName));
										if("".equals(flowSourceOne)){ //全选时
											checkFowSourceOne = checkFowSourceOne + "'" + operName+"',";
										}
									}
								
								}
							}
						}
						
						if("".equals(flowSourceOne)){ //全选时
							flowSourceOne = checkFowSourceOne;
						}
						if(flowSourceOne.endsWith(",")){
							flowSourceOne = flowSourceOne.substring(0,flowSourceOne.lastIndexOf(","));
						}
					}
					model.add("flowSourceOneList",finalFlowSourceOneList);
					url.append("&flowSourceOne="+flowSourceOne);
					model.add("flowSourceOne",flowSourceOne);
				
					
					if(!"".equals(flowSourceOne)){
						condition.append(" and "+flowSourceEnames[0]+" in("+flowSourceOne+") ");
						inCondition.append(" and "+flowSourceEnames[0]+" in("+flowSourceOne+") ");
					}else{ 
						/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
						boolean checkGB = false;
						for(int i = 0 ; i < flowSourceEnames.length; i ++){
							String check = flowSourceEnames[i];
							if(groupBy.contains(check)){
								checkGB = true;
								break;
							}
						}
						String flowSourceOneDeal = flowSourceOne;
						if(checkGB){
							flowSourceOneDeal = " != 'all' ";
						}else{
							flowSourceOneDeal = " = 'all' ";
						}
						condition.append(" and "+flowSourceEnames[0] + flowSourceOneDeal);
						inCondition.append(" and "+flowSourceEnames[0] + flowSourceOneDeal);
					}
					
					//二级来源
					String flowSourceTwo = ServletRequestUtils.getStringParameter(request,"flowSourceTwo" ,"");
					url.append("&flowSourceTwo="+flowSourceTwo);
					model.add("flowSourceTwo",flowSourceTwo);
					if(flowSourceLevel >= 2){
						//二级来源列表
						if(!"".equals(flowSourceOne) && flowSourceOne.split(",").length == 1){
							List<NetFlowSource> flowSourceTwoList = netFlowSourceService.getSource2List(StringUtils.strip(flowSourceOne, "' "));
							model.add("flowSourceTwoList",flowSourceTwoList);
						}
						if(!"".equals(flowSourceTwo)){
							condition.append(" and "+flowSourceEnames[1]+" in("+flowSourceTwo+") ");
							inCondition.append(" and "+flowSourceEnames[1]+" in("+flowSourceTwo+") ");
						}else{ // 向上汇总报表   
							/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
							boolean checkGB = false;
							for(int i = 1 ; i < flowSourceEnames.length; i ++){
								String check = flowSourceEnames[i];
								if(groupBy.contains(check)){
									checkGB = true;
									break;
								}
							}
	  						String flowSourceTwoDeal = flowSourceTwo;
							if(checkGB){
								flowSourceTwoDeal = " != 'all' ";
							}else{
								flowSourceTwoDeal = " = 'all' ";
							}
							condition.append(" and "+flowSourceEnames[1] + flowSourceTwoDeal);
							inCondition.append(" and "+flowSourceEnames[1] + flowSourceTwoDeal);
						}
					}
					
					//三级来源
					String flowSourceThree = ServletRequestUtils.getStringParameter(request,"flowSourceThree" ,"");
					url.append("&flowSourceThree="+flowSourceThree);
					model.add("flowSourceThree",flowSourceThree);
				
					if(flowSourceLevel >= 3 ){
						//三级来源列表
						if(!"".equals(flowSourceTwo) && flowSourceOne.split(",").length == 1 && flowSourceTwo.split(",").length == 1){
							List<NetFlowSource> flowSourceThreeList = netFlowSourceService.getSource3List(StringUtils.strip(flowSourceOne, "' "),StringUtils.strip(flowSourceTwo, "' ") );
							model.add("flowSourceThreeList",flowSourceThreeList);
						}
						if(!"".equals(flowSourceThree)){
							condition.append(" and "+flowSourceEnames[2]+" in("+flowSourceThree+") ");
							inCondition.append(" and "+flowSourceEnames[2]+" in("+flowSourceThree+") ");
						}else{ // 向上汇总报表   
							/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
							boolean checkGB = false;
							for(int i = 2 ; i < flowSourceEnames.length; i ++){
								String check = flowSourceEnames[i];
								if(groupBy.contains(check)){
									checkGB = true;
									break;
								}
							}
	  						String flowSourceThreeDeal = flowSourceThree;
							if(checkGB){
								flowSourceThreeDeal = " != 'all' ";
							}else{
								flowSourceThreeDeal = " = 'all' ";
							}
							condition.append(" and "+flowSourceEnames[2] + flowSourceThreeDeal);
							inCondition.append(" and "+flowSourceEnames[2] + flowSourceThreeDeal);
						}
					}
					
					
					//四级来源
					String flowSourceFour = ServletRequestUtils.getStringParameter(request,"flowSourceFour" ,"");
					url.append("&flowSourceFour="+flowSourceFour);
					model.add("flowSourceFour",flowSourceFour);
					
					if(flowSourceLevel >= 4 ){
						//四级来源列表
						if(!"".equals(flowSourceThree) && flowSourceOne.split(",").length == 1 && flowSourceTwo.split(",").length == 1 &&  flowSourceThree.split(",").length == 1){
							List<NetFlowSource> flowSourceFourList = netFlowSourceService.getSource4List(StringUtils.strip(flowSourceOne, "' "),StringUtils.strip(flowSourceTwo, "' "),StringUtils.strip(flowSourceThree, "' ") );
							model.add("flowSourceFourList",flowSourceFourList);
						}
						
						if(!"".equals(flowSourceFour)){
							condition.append(" and "+flowSourceEnames[3]+" in("+flowSourceFour+") ");
							inCondition.append(" and "+flowSourceEnames[3]+" in("+flowSourceFour+") ");
						}else{ // 向上汇总报表   
							/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
							boolean checkGB = false;
							for(int i = 3 ; i < flowSourceEnames.length; i ++){
								String check = flowSourceEnames[i];
								if(groupBy.contains(check)){
									checkGB = true;
									break;
								}
							}
	  						String flowSourceFourDeal = flowSourceFour;
							if(checkGB){
								flowSourceFourDeal = " != 'all' ";
							}else{
								flowSourceFourDeal =" = 'all' ";
							}
							condition.append(" and "+flowSourceEnames[3] + flowSourceFourDeal);
							inCondition.append(" and "+flowSourceEnames[3] + flowSourceFourDeal);
						}
					}
					
					break;
					
				case 21://驾校一点通来源级联组件  （向上汇总）
					int jxedtSourceLevel = 0; //级联层数数
					String jxedtFlowSourcePlatform = "";//平台
					for(String temp : vo.getDetailValue().split(";")){
						if(temp.split(":")[0].equals("level")){
							jxedtSourceLevel = Integer.parseInt(temp.split(":")[1]);
						}
						if(temp.split(":")[0].equals("platform")){
							jxedtFlowSourcePlatform = temp.split(":")[1];
						}
					}
					String[] jxedtSourceEnames = sename.split(";");
					
					//source1
					String jxedtSourceOne = ServletRequestUtils.getStringParameter(request,"jxedtSourceOne" ,"");
					url.append("&jxedtSourceOne="+jxedtSourceOne);
					model.add("jxedtSourceOne",jxedtSourceOne);
					List<JxedtFlowSource> jxedtSourceOneList = jxedtFlowSourceService.getSource1List(jxedtFlowSourcePlatform);
					model.add("jxedtSourceOneList",jxedtSourceOneList);
					
					if(!"".equals(jxedtSourceOne)){
						condition.append(" and "+jxedtSourceEnames[0]+" in("+jxedtSourceOne+") ");
						inCondition.append(" and "+jxedtSourceEnames[0]+" in("+jxedtSourceOne+") ");
					}else if("".equals(jxedtSourceOne)){ 
						/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
						boolean checkGB = false;
						for(int i = 0 ; i < jxedtSourceEnames.length; i ++){
							String check = jxedtSourceEnames[i];
							if(groupBy.contains(check)){
								checkGB = true;
								break;
							}
						}
						String jxedtSourceOneDeal = jxedtSourceOne;
						if(checkGB){
							jxedtSourceOneDeal = " != 'all' ";
						}else{
							jxedtSourceOneDeal = " = 'all' ";
						}
						condition.append(" and "+jxedtSourceEnames[0] + jxedtSourceOneDeal);
						inCondition.append(" and "+jxedtSourceEnames[0] + jxedtSourceOneDeal);
					}
					
					//source2
					String jxedtSourceTwo = ServletRequestUtils.getStringParameter(request,"jxedtSourceTwo" ,"");
					if(jxedtSourceLevel >= 2){
						url.append("&jxedtSourceTwo="+jxedtSourceTwo);
						model.add("jxedtSourceTwo",jxedtSourceTwo);
						if(!"".equals(jxedtSourceOne) && jxedtSourceOne.split(",").length == 1){
							List<JxedtFlowSource> jxedtSourceTwoList = jxedtFlowSourceService.getSource2List(jxedtFlowSourcePlatform,StringUtils.strip(jxedtSourceOne, "' "));
							model.add("jxedtSourceTwoList",jxedtSourceTwoList);
						}
						if(!"".equals(jxedtSourceTwo)){
							condition.append(" and "+jxedtSourceEnames[1]+" in("+jxedtSourceTwo+") ");
							inCondition.append(" and "+jxedtSourceEnames[1]+" in("+jxedtSourceTwo+") ");
						}else if("".equals(jxedtSourceTwo)){ // 向上汇总报表   
							/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
							boolean checkGB = false;
							for(int i = 1 ; i < jxedtSourceEnames.length; i ++){
								String check = jxedtSourceEnames[i];
								if(groupBy.contains(check)){
									checkGB = true;
									break;
								}
							}
	  						String jxedtSourceTwoDeal = jxedtSourceTwo;
							if(checkGB){
								jxedtSourceTwoDeal = " != 'all' ";
							}else{
								jxedtSourceTwoDeal = " = 'all' ";
							}
							condition.append(" and " + jxedtSourceEnames[1] + jxedtSourceTwoDeal);
							inCondition.append(" and " + jxedtSourceEnames[1] + jxedtSourceTwoDeal);
						}
					}
					break;
					
				case 22://中华英才流量来源级联组件  （向上汇总型）
					int chrFlowSourceLevel = 0; //级联层数数
					String chrFlowSourcePlatform = ""; //平台类型
					for(String temp : vo.getDetailValue().split(";")){
						if(temp.split(":")[0].equals("level")){
							chrFlowSourceLevel = Integer.parseInt(temp.split(":")[1]);
						}
						if(temp.split(":")[0].equals("platform")){
							chrFlowSourcePlatform = temp.split(":")[1];
						}
					}
					String[] chrFlowSourceEnames = sename.split(";");
					
					//一级来源  
					String chrSourceOne = ServletRequestUtils.getStringParameter(request,"chrSourceOne" ,"");
					url.append("&chrSourceOne="+chrSourceOne);
					model.add("chrSourceOne",chrSourceOne);
					
					//一级来源列表
					List<ChinahrSource> chrSourceOneList = chinahrSourceService.getSource1(chrFlowSourcePlatform);
					model.add("chrSourceOneList",chrSourceOneList);
					
					if(!"".equals(chrSourceOne)){
						condition.append(" and "+chrFlowSourceEnames[0]+" in("+chrSourceOne+") ");
						inCondition.append(" and "+chrFlowSourceEnames[0]+" in("+chrSourceOne+") ");
					
					}else{ 
						/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
						boolean checkGB = false;
						for(int i = 0 ; i < chrFlowSourceEnames.length; i ++){
							String check = chrFlowSourceEnames[i];
							if(groupBy.contains(check)){
								checkGB = true;
								break;
							}
						}
						String chrSourceOneDeal = chrSourceOne;
						if(checkGB){
							chrSourceOneDeal = " != 'all' ";
						}else{
							chrSourceOneDeal = " = 'all' ";
						}
						condition.append(" and "+chrFlowSourceEnames[0] + chrSourceOneDeal);
						inCondition.append(" and "+chrFlowSourceEnames[0] + chrSourceOneDeal);
					}
					
					
					//二级来源
					String chrSourceTwo = ServletRequestUtils.getStringParameter(request,"chrSourceTwo" ,"");
					url.append("&chrSourceTwo="+chrSourceTwo);
					model.add("chrSourceTwo",chrSourceTwo);
					if(chrFlowSourceLevel >= 2){
						//二级来源列表
						if(!"".equals(chrSourceOne) && chrSourceOne.split(",").length == 1){
							List<ChinahrSource> chrSourceTwoList = chinahrSourceService.getSource2(chrFlowSourcePlatform,StringUtils.strip(chrSourceOne, "' "));
							model.add("chrSourceTwoList",chrSourceTwoList);
						}
						if(!"".equals(chrSourceTwo)){
							condition.append(" and "+chrFlowSourceEnames[1]+" in("+chrSourceTwo+") ");
							inCondition.append(" and "+chrFlowSourceEnames[1]+" in("+chrSourceTwo+") ");
						}else{ // 向上汇总报表   
							/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
							boolean checkGB = false;
							for(int i = 1 ; i < chrFlowSourceEnames.length; i ++){
								String check = chrFlowSourceEnames[i];
								if(groupBy.contains(check)){
									checkGB = true;
									break;
								}
							}
	  						String chrSourceTwoDeal = chrSourceTwo;
							if(checkGB){
								chrSourceTwoDeal = " != 'all' ";
							}else{
								chrSourceTwoDeal = " = 'all' ";
							}
							condition.append(" and "+chrFlowSourceEnames[1] + chrSourceTwoDeal);
							inCondition.append(" and "+chrFlowSourceEnames[1] + chrSourceTwoDeal);
						}
					}
					
					
					//三级来源
					String chrSourceThree = ServletRequestUtils.getStringParameter(request,"chrSourceThree" ,"");
					url.append("&chrSourceThree="+chrSourceThree);
					model.add("chrSourceThree",chrSourceThree);
					
					if(chrFlowSourceLevel >= 3 ){
						//三级来源列表
						if(!"".equals(chrSourceTwo) && chrSourceOne.split(",").length == 1 && chrSourceTwo.split(",").length == 1){
							List<ChinahrSource> chrSourceThreeList = chinahrSourceService.getSource3(chrFlowSourcePlatform,StringUtils.strip(chrSourceOne, "' "),StringUtils.strip(chrSourceTwo, "' ") );
							model.add("chrSourceThreeList",chrSourceThreeList);
						}
						if(!"".equals(chrSourceThree)){
							condition.append(" and "+chrFlowSourceEnames[2]+" in("+chrSourceThree+") ");
							inCondition.append(" and "+chrFlowSourceEnames[2]+" in("+chrSourceThree+") ");
						}else{ // 向上汇总报表   
							/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
							boolean checkGB = false;
							for(int i = 2 ; i < chrFlowSourceEnames.length; i ++){
								String check = chrFlowSourceEnames[i];
								if(groupBy.contains(check)){
									checkGB = true;
									break;
								}
							}
	  						String showCHRSourceThreeDeal = chrSourceThree;
							if(checkGB){
								showCHRSourceThreeDeal = " != 'all' ";
							}else{
								showCHRSourceThreeDeal = " = 'all' ";
							}
							condition.append(" and "+chrFlowSourceEnames[2] + showCHRSourceThreeDeal);
							inCondition.append(" and "+chrFlowSourceEnames[2] + showCHRSourceThreeDeal);
						}
					}
					
					
					//四级来源
					String chrSourceFour = ServletRequestUtils.getStringParameter(request,"chrSourceFour" ,"");
					url.append("&chrSourceFour="+chrSourceFour);
					model.add("chrSourceFour",chrSourceFour);
					if(chrFlowSourceLevel >= 4 ){
						//四级来源列表
						if(!"".equals(chrSourceThree) && chrSourceOne.split(",").length == 1 && chrSourceTwo.split(",").length == 1 &&  chrSourceThree.split(",").length == 1){
							List<ChinahrSource> chrSourceFourList = chinahrSourceService.getSource4(chrFlowSourcePlatform,StringUtils.strip(chrSourceOne, "' "),StringUtils.strip(chrSourceTwo, "' "),StringUtils.strip(chrSourceThree, "' ") );
							model.add("chrSourceFourList",chrSourceFourList);
						}
						
						if(!"".equals(chrSourceFour)){
							condition.append(" and "+chrFlowSourceEnames[3]+" in("+chrSourceFour+") ");
							inCondition.append(" and "+chrFlowSourceEnames[3]+" in("+chrSourceFour+") ");
						}else{ // 向上汇总报表   
							/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
							boolean checkGB = false;
							for(int i = 3 ; i < chrFlowSourceEnames.length; i ++){
								String check = chrFlowSourceEnames[i];
								if(groupBy.contains(check)){
									checkGB = true;
									break;
								}
							}
	  						String chrSourceFourDeal = chrSourceFour;
							if(checkGB){
								chrSourceFourDeal = " != 'all' ";
							}else{
								chrSourceFourDeal =" = 'all' ";
							}
							condition.append(" and "+chrFlowSourceEnames[3] + chrSourceFourDeal);
							inCondition.append(" and "+chrFlowSourceEnames[3] + chrSourceFourDeal);
						}
					}
					
					break;
					
				case 23://中华英才行业级联组件  （向上汇总型）
					int chrIndustryLevel = 0; //级联层数数
					for(String temp : vo.getDetailValue().split(";")){
						if(temp.split(":")[0].equals("level")){
							chrIndustryLevel = Integer.parseInt(temp.split(":")[1]);
						}
					}
					String[] chrIndustryEnames = sename.split(";");
					
					//一级来源  
					String chrIndustryOne = ServletRequestUtils.getStringParameter(request,"chrIndustryOne" ,"");
					url.append("&chrIndustryOne="+chrIndustryOne);
					model.add("chrIndustryOne",chrIndustryOne);
					
					//一级来源列表
					List<ChinahrIndustry> chrIndustryOneList = chinahrIndustryService.getAllCate1();
					model.add("chrIndustryOneList",chrIndustryOneList);
					
					if(!"".equals(chrIndustryOne)){
						condition.append(" and "+chrIndustryEnames[0]+" in("+chrIndustryOne+") ");
						inCondition.append(" and "+chrIndustryEnames[0]+" in("+chrIndustryOne+") ");
					}else{ 
						/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
						boolean checkGB = false;
						for(int i = 0 ; i < chrIndustryEnames.length; i ++){
							String check = chrIndustryEnames[i];
							if(groupBy.contains(check)){
								checkGB = true;
								break;
							}
						}
						String chrIndustryOneDeal = chrIndustryOne;
						if(checkGB){
							chrIndustryOneDeal = " != 'all' ";
						}else{
							chrIndustryOneDeal = " = 'all' ";
						}
						condition.append(" and "+chrIndustryEnames[0] + chrIndustryOneDeal);
						inCondition.append(" and "+chrIndustryEnames[0] + chrIndustryOneDeal);
					}
					
					
					//二级来源
					String chrIndustryTwo = ServletRequestUtils.getStringParameter(request,"chrIndustryTwo" ,"");
					url.append("&chrIndustryTwo="+chrIndustryTwo);
					model.add("chrIndustryTwo",chrIndustryTwo);
					if(chrIndustryLevel >= 2){
						//二级来源列表
						if(!"".equals(chrIndustryOne) && chrIndustryOne.split(",").length == 1){
							List<ChinahrIndustry> chrIndustryTwoList = chinahrIndustryService.getAllCate2(StringUtils.strip(chrIndustryOne, "' "));
							model.add("chrIndustryTwoList",chrIndustryTwoList);
						}
						if(!"".equals(chrIndustryTwo)){
							condition.append(" and "+chrIndustryEnames[1]+" in("+chrIndustryTwo+") ");
							inCondition.append(" and "+chrIndustryEnames[1]+" in("+chrIndustryTwo+") ");
						}else{ // 向上汇总报表   
							/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
							boolean checkGB = false;
							for(int i = 1 ; i < chrIndustryEnames.length; i ++){
								String check = chrIndustryEnames[i];
								if(groupBy.contains(check)){
									checkGB = true;
									break;
								}
							}
	  						String chrIndustryTwoDeal = chrIndustryTwo;
							if(checkGB){
								chrIndustryTwoDeal = " != 'all' ";
							}else{
								chrIndustryTwoDeal = " = 'all' ";
							}
							condition.append(" and "+chrIndustryEnames[1] + chrIndustryTwoDeal);
							inCondition.append(" and "+chrIndustryEnames[1] + chrIndustryTwoDeal);
						}
					}
					
					break;
					
					
				case 24://中华英才职位级联组件  （向上汇总型）
					int chrJobLevel = 0; //级联层数数
					for(String temp : vo.getDetailValue().split(";")){
						if(temp.split(":")[0].equals("level")){
							chrJobLevel = Integer.parseInt(temp.split(":")[1]);
						}
					}
					String[] chrJobEnames = sename.split(";");
					
					//一级来源  
					String chrJobOne = ServletRequestUtils.getStringParameter(request,"chrJobOne" ,"");
					url.append("&chrJobOne="+chrJobOne);
					model.add("chrJobOne",chrJobOne);
					
					//一级来源列表
					List<ChinahrJob> chrJobOneList = chinahrJobService.getAllCate1();
					model.add("chrJobOneList",chrJobOneList);
					
					if(!"".equals(chrJobOne)){
						condition.append(" and "+chrJobEnames[0]+" in("+chrJobOne+") ");
						inCondition.append(" and "+chrJobEnames[0]+" in("+chrJobOne+") ");
					
					}else{ 
						/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
						boolean checkGB = false;
						for(int i = 0 ; i < chrJobEnames.length; i ++){
							String check = chrJobEnames[i];
							if(groupBy.contains(check)){
								checkGB = true;
								break;
							}
						}
						String chrJobOneDeal = chrJobOne;
						if(checkGB){
							chrJobOneDeal = " != 'all' ";
						}else{
							chrJobOneDeal = " = 'all' ";
						}
						condition.append(" and "+chrJobEnames[0] + chrJobOneDeal);
						inCondition.append(" and "+chrJobEnames[0] + chrJobOneDeal);
					}
					
					
					//二级来源
					String chrJobTwo = ServletRequestUtils.getStringParameter(request,"chrJobTwo" ,"");
					url.append("&chrJobTwo="+chrJobTwo);
					model.add("chrJobTwo",chrJobTwo);
					if(chrJobLevel >= 2){
						//二级来源列表
						if(!"".equals(chrJobOne) && chrJobOne.split(",").length == 1){
							List<ChinahrJob> chrJobTwoList = chinahrJobService.getCate2(StringUtils.strip(chrJobOne, "' "));
							model.add("chrJobTwoList",chrJobTwoList);
						}
						if(!"".equals(chrJobTwo)){
							condition.append(" and "+chrJobEnames[1]+" in("+chrJobTwo+") ");
							inCondition.append(" and "+chrJobEnames[1]+" in("+chrJobTwo+") ");
						}else{ // 向上汇总报表   
							/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
							boolean checkGB = false;
							for(int i = 1 ; i < chrJobEnames.length; i ++){
								String check = chrJobEnames[i];
								if(groupBy.contains(check)){
									checkGB = true;
									break;
								}
							}
	  						String chrJobTwoDeal = chrJobTwo;
							if(checkGB){
								chrJobTwoDeal = " != 'all' ";
							}else{
								chrJobTwoDeal = " = 'all' ";
							}
							condition.append(" and "+chrJobEnames[1] + chrJobTwoDeal);
							inCondition.append(" and "+chrJobEnames[1] + chrJobTwoDeal);
						}
					}
					
					
					//三级来源
					String chrJobThree = ServletRequestUtils.getStringParameter(request,"chrJobThree" ,"");
					url.append("&chrJobThree="+chrJobThree);
					model.add("chrJobThree",chrJobThree);
					
					if(chrJobLevel >= 3 ){
						//三级来源列表
						if(!"".equals(chrJobTwo) && chrJobOne.split(",").length == 1 && chrJobTwo.split(",").length == 1){
							List<ChinahrJob> chrJobThreeList = chinahrJobService.getCate3(StringUtils.strip(chrJobOne, "' "),StringUtils.strip(chrJobTwo, "' ") );
							model.add("chrJobThreeList",chrJobThreeList);
						}
						if(!"".equals(chrJobThree)){
							condition.append(" and "+chrJobEnames[2]+" in("+chrJobThree+") ");
							inCondition.append(" and "+chrJobEnames[2]+" in("+chrJobThree+") ");
						}else{ // 向上汇总报表   
							/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
							boolean checkGB = false;
							for(int i = 2 ; i < chrJobEnames.length; i ++){
								String check = chrJobEnames[i];
								if(groupBy.contains(check)){
									checkGB = true;
									break;
								}
							}
	  						String showchrJobThreeDeal = chrJobThree;
							if(checkGB){
								showchrJobThreeDeal = " != 'all' ";
							}else{
								showchrJobThreeDeal = " = 'all' ";
							}
							condition.append(" and "+chrJobEnames[2] + showchrJobThreeDeal);
							inCondition.append(" and "+chrJobEnames[2] + showchrJobThreeDeal);
						}
					}
					
					break;
					
				}
			}
			model.add("hasSubMail",1);
//			hasSubMail = true;
			String ordervalue  =  ServletRequestUtils.getStringParameter(request, "ordervalue","");//排序值
			String ordertype  =  ServletRequestUtils.getStringParameter(request, "ordertype","");//排序方式
			int pageindex = ServletRequestUtils.getIntParameter(request,"pageindex",1);//页数。
			int down = ServletRequestUtils.getIntParameter(request,"down",0);//下载
			int rijun = ServletRequestUtils.getIntParameter(request,"rijun",-1);//日均
			url.append("&groupBy="+groupBy);
			url.append("&ordervalue="+ordervalue);
			url.append("&ordertype="+ordertype);
			
			model.add("ordervalue",ordervalue);
			model.add("ordertype",ordertype);
			model.add("groupBy",groupBy);
			model.add("pageindex",pageindex);
			model.add("down",down);
			model.add("menuId",pathid);
			//维度处理
			if(!"".equals(groupBy)){
				log.info("groupBy-1: "+groupBy);
				if(groupBy.split(",").length > 1){
					//查询维度排序 by 默认ID
					List<String>  tempGb = new ArrayList<String>();
					for(String gb : groupBy.split(",")){
						tempGb.add(gb.replace(":", "_"));
					}
					tempGb = SortUtil.AscByKey_int(tempGb);
					groupBy = "";
					for(String gb : tempGb){
						groupBy = groupBy + gb.substring(gb.indexOf("_")+1)+",";
					}
					groupBy = groupBy.substring(0,groupBy.lastIndexOf(","));
				}else{
					groupBy = groupBy.substring(groupBy.indexOf(":")+1);
				}
				log.info("groupBy-2: "+groupBy);
			}
			
			List<String> cols = new LinkedList<String>();  //查询显示字段
			List<String> cnameList =  new ArrayList<String>();//中文名
			List<IRColumns>  irColList = IRColumnsService.getColsByReportId(irReport.getId());
			
			if(irReport.getTemplateType() == 1){  //默认显示全部字段
				for(IRColumns column : irColList){
					cols.add(column.getEname());
					cnameList.add(column.getCname()+":"+column.getColType()+":"+column.getEname()); //字段中文名,字段类型,英文名
				}
			}else if(irReport.getTemplateType() == 2){  //根据选择 查询、显示字段
				String colsSelect  =  ServletRequestUtils.getStringParameter(request, "colsSelect","");//查询项勾选值
				HashSet<String> colsSelectSet = new HashSet<String>();
				String[] colsTempArray = colsSelect.split(",");
				for (String col : colsTempArray) {
					colsSelectSet.add(col);
				}
					
				for(IRColumns column : irColList){
					if(colsSelectSet.contains(column.getEname()) || "groupBy".equals(column.getEname())){
						cols.add(column.getEname());
						cnameList.add(column.getCname()+":"+column.getColType()+":"+column.getEname()); //字段中文名及字段类型
						/*if(column.getIsOrderBy() == 1){
							sortList.add(column.getEname()+","+column.getCname());
						}*/
					}
				}
				model.add("colsSelect",colsSelect);
				url.append("&colsSelect="+colsSelect);
			}
			//groupby不为空时 && 表头集合第一个为分组维度时
			if(!"".equals(groupBy) && cnameList.get(0).contains("维度") ){
				//多groupby处理
				List<String> newCnameList =  new ArrayList<String>();
				for(int i = 0 ; i < groupBy.split(",").length; i ++){
					String gb = groupBy.split(",")[i];
					newCnameList.add(gbMap.get(gb)+":0");
				}
				cnameList.remove(0);
				newCnameList.addAll(cnameList);
				cnameList = newCnameList;
			}
			
			model.add("cnameList",cnameList);
			
			//排序值处理
			String orderBy = "";
			if(!"".equals(ordervalue) && !"".equals(ordertype) ){
				orderBy = "order by "+ordervalue +" "+ ordertype;
			}else if(!"".equals(groupBy)){
				orderBy = "order by "+groupBy.split(",")[0];
			}else{
				String dateName = "";  //日期绑定字段
				for(String temp : specialValues.toString().split(";")){
					String key = temp.split(":")[0];
					String value = temp.split(":")[1];
					if("dateName".equals(key)){
						dateName = value;
					}
				}
				orderBy = "order by "+ dateName ;
			}
			
			String dateratio  =  ServletRequestUtils.getStringParameter(request, "dateratio","");
			String dailyselect  =  ServletRequestUtils.getStringParameter(request, "dailyselect","");
			int dailysum=1;
			boolean hasStatDate=groupBy.contains("stat_date")||groupBy.contains("statDate")||groupBy.contains("vDate"); //包含"每天,日期"选项
			boolean dayRatio=false,weekRatio=false; //是否选了同环比
			if(hasStatDate==false)
			{
				dateratio="";
			}else {
				dailyselect="";
			}
			if(!"".equals(dateratio))
			{
				if(dateratio.equals("allRatio"))
				{
					dayRatio = true;        	//日同比
					weekRatio = true;			//周环比
					url.append("&dateratio=allRatio");
				}else if(dateratio.equals("dayRatio"))
				{
					dayRatio = true;        	//日同比
					url.append("&dateratio=dayRatio");
					
				}else if(dateratio.equals("weekRatio"))
				{
					weekRatio = true;			//周环比
					url.append("&dateratio=weekRatio");
					
				}
				
			}
			if((rijun==1)&&!("".equals(dailyselect)))//日均
			{
				String start = ServletRequestUtils.getStringParameter(request, "startDate","");
				String end = ServletRequestUtils.getStringParameter(request, "endDate","");
				dailysum=(int)DateUtil.getDistDates(DateUtil.strToDate(end, "yyyy-MM-dd"), DateUtil.strToDate(start, "yyyy-MM-dd"))+1;
				drills=null;
			}
			if((rijun==0)&&("".equals(dailyselect))&&(!"".equals(ordertype)))//日均排序
			{
				String start = ServletRequestUtils.getStringParameter(request, "startDate","");
				String end = ServletRequestUtils.getStringParameter(request, "endDate","");
				dailysum=(int)DateUtil.getDistDates(DateUtil.strToDate(end, "yyyy-MM-dd"), DateUtil.strToDate(start, "yyyy-MM-dd"))+1;
				drills=null;
			}
			url.append("&dailyselect="+dailyselect);
			model.add("dailyselect",dailyselect);
			url.append("&rijun="+rijun);
			model.add("rijun",rijun);
			String gbs[] = groupBy.split(",");
			int statgbsindex=0;
			for (int i = 0; i < gbs.length; i++) { // 日期维度所在位置
				if (gbs[i].equals("stat_date")||gbs[i].equals("statDate")||gbs[i].equals("vDate")) {
					statgbsindex=i;
					break;
				}
			}
			url.append("&hasStatDate=hasStatDate");
			model.add("gbCount",gbs.length);
			if(down == 0){//查询
				String tablePattern=irReport.getTableName(); //数据表格式
				Paginate<String> pList = IntReportMainService.IRsearchValues(irReport, condition.toString(), cols,drills, orderBy, groupBy, 50, pageindex,specialValues.toString(),dailysum);
				model.add("querylength",pList.getRecordCount());
				String submailCondition=inCondition.toString();
				//同比、环比
				if (hasStatDate&&(dayRatio||weekRatio)) {
					cols.add(0, "groupBy");
					HashMap<String, TreeSet<String>> gbValuesMap = new HashMap<String, TreeSet<String>>();
					List<String> items = pList.getItems(); // 获得第一次查询结果集
//					log.info("第一次查询："+items.get(0));
					for (String recode : items) { // 对每一条记录提取维度值，放入对应的集合中
						String cells[] = recode.split(";", gbs.length + 1);
						for (int i = 0; i < gbs.length; i++) { // 维度
							TreeSet<String> gbValues = gbValuesMap.get(gbs[i]);
							if (gbValues == null){
								gbValues = new TreeSet<String>();
							}
								
							if (i==statgbsindex) { // 当为时间维度时
								String date = cells[i].split(",")[0];
								gbValues.add(date);
								if(dayRatio){
									gbValues.add(DateUtil.strToStrBefore(date,"yyyy-MM-dd", 1));
								}
								if(weekRatio){
									gbValues.add(DateUtil.strToStrBefore(date,"yyyy-MM-dd", 7));
								}
								model.add("statgrpindex",statgbsindex);
							} else{// 不是时间维度
								gbValues.add(cells[i].split(",")[0]);
							}
							gbValuesMap.put(gbs[i], gbValues);
						}
					}
					specialValues = new StringBuffer();  //startDate;endDate;dateName
					if (items != null && !items.isEmpty())  //重组sql条件
						for (int i = 0; i < gbs.length; i++) {
							inCondition.append(" and " + gbs[i] + " in(");
							TreeSet<String> gbValues = gbValuesMap.get(gbs[i]);
							if (i==statgbsindex) {
								specialValues.append("startDate:"+ gbValues.first() + ";");
								specialValues.append("endDate:"	+ gbValues.last() + ";");
								specialValues.append("dateName:" + gbs[i] + ";");
							}
							Iterator<String> iter = gbValues.iterator();
							while (iter.hasNext()) {
								String value=iter.next();
								if("--".equals(value)){
									inCondition.append("''");
								}else
									inCondition.append("'" +value+ "'");
								if (iter.hasNext())
									inCondition.append(",");
							}
							inCondition.append(")");
						}
//					log.info("condition: " + condition+ "\ninCondiction: " + inCondition);
					//计算环同比所需的结果集，以map形式返回
					irReport.setTableName(tablePattern);
					HashMap<String,String> keyValue=IntReportMainService.IRsearchValuesNonPage(irReport,inCondition.toString(), cols,drills, groupBy,specialValues.toString());
//					log.info(keyValue.keySet());
					model.add("dateratio",dateratio);
//					model.add("hasComp",hasComp);
					model.add("gbValueMap", keyValue);
				}
				model.add("hasStatDate",hasStatDate);
				
				//流量来源报表  来源字段需要通过对应的中英文字典翻译
				int menuId = irReport.getMenuId();
				if(!pList.getItems().isEmpty() && (menuId>=269 && menuId <= 272) && groupBy.contains("source") ){
					pList = IntReportMainService.flowSourceNameTran(pList);
				}
				
				
				/**报表订阅  如果此次查询不为空 ，
				 *	则将此次查询相关条件等保存(以用户ID&报表ID为Key)
				 *  阅操待用户进行订作时再取出，存入DB。
				 *  不将查询的各类参数直接传入页面再提交是为了页面安全，不暴露数据库字段
				 */
				if(null != pList.getItems() && !pList.getItems().isEmpty()){
					int userId = (int)spu.getUserByCookie(request).getId();
					int reportId = irReport.getId();
					
					IRSubMailVo vo = new IRSubMailVo();
					UserSubMailVo vouser =new UserSubMailVo();
					vouser.setUserId(userId);
					vouser.setReportId(reportId);
					vouser.setSearchCondition(submailCondition.toString());
					vouser.setDayRatio(dayRatio==true?1:0);
					vouser.setWeekRatio(weekRatio==true?1:0);
					vo.setUserId(userId);
					vo.setReportId(reportId);
					vo.setSearchCondition(submailCondition.toString());
					vo.setDayRatio(dayRatio==true?1:0);
					vo.setWeekRatio(weekRatio==true?1:0);
					StringBuffer searchCols = new StringBuffer();
					for(String col : cols){
						searchCols.append(col+"&");
					}
					vouser.setSearchCols(searchCols.toString());
					vouser.setSearchOrderBy(orderBy);
					vouser.setSearchGroupBy(groupBy);
					vouser.setSearchSpeValue(specialValues.toString());
					vo.setSearchCols(searchCols.toString());
					vo.setSearchOrderBy(orderBy);
					vo.setSearchGroupBy(groupBy);
					vo.setSearchSpeValue(specialValues.toString());
					
					StringBuffer searchTitles = new StringBuffer();
					for(String cname : cnameList){
						searchTitles.append(cname+"&");
					}
					vouser.setSearchTitles(searchTitles.toString());
					vo.setSearchTitles(searchTitles.toString());
					IntReportToolsController.subEmailTable.put(userId+reportId, vo);
					IntReportToolsController.userEmailTable.put(userId+reportId, vouser);
				}
				
				
				
				model.add("pList",pList);
				model.add("rsList",pList.getItems());	
				model.add("paramurl",url.toString());//分页URL
			}else if(down == 1){	//下载
				pageindex = -1; 
				String tableName = irReport.getReportName();
				String tablePattern=irReport.getTableName(); //数据表格式，解决日比周比跨表问题
				Paginate<String> pList = IntReportMainService.IRsearchValues(irReport, condition.toString(), cols,drills, orderBy, groupBy, 50, pageindex,specialValues.toString(),dailysum);
				model.add("querylength",pList.getRecordCount());
				SXSSFWorkbook wwb = null;
				StringBuilder ratioCondiction=new StringBuilder();
				if (hasStatDate&&(dayRatio||weekRatio)) {  //日环比选项被勾选
					cols.add(0, "groupBy");
					String start = ServletRequestUtils.getStringParameter(request, "startDate","");
					String end = ServletRequestUtils.getStringParameter(request, "endDate","");
					String startDate=null,endDate=null;
					if(weekRatio){ //有周同比
						startDate=DateUtil.strToStrBefore(start,"yyyy-MM-dd", 7);
						if(dayRatio) //也有日环比
							endDate=DateUtil.strToStrBefore(start,"yyyy-MM-dd", 1);
						else{      //只有周同比
							String date1=DateUtil.strToStrBefore(start,"yyyy-MM-dd", 1);
							String date2=DateUtil.strToStrBefore(end,"yyyy-MM-dd", 7);
							int result=date1.compareTo(date2);
							endDate=result>0?date2:date1;
						}
						ratioCondiction.append(" and "+gbs[statgbsindex]+">='"+startDate+"' ");
						ratioCondiction.append("and "+gbs[statgbsindex]+"<='"+endDate+"' ");
					}else{ //只有日环比
						startDate=DateUtil.strToStrBefore(start,"yyyy-MM-dd", 1);
						endDate=DateUtil.strToStrBefore(start,"yyyy-MM-dd", 1);
						ratioCondiction.append("and "+gbs[statgbsindex]+"='"+endDate+"' ");
					}
					ratioCondiction.append(inCondition);
					//下载bug修复，原下载中，若周比日期跨月则下载数据错误
					//还原报表原有样式
					irReport.setTableName(tablePattern);
					//替换special中的初始日期
					String specialStr=specialValues.toString();
					if(specialStr.contains("startDate"))
					{
						String temp[]=specialStr.split(";");
						specialStr="";
						for(int t=0;t<temp.length;t++){
							if(temp[t].contains("startDate"))
							{
								temp[t]="startDate:"+startDate;
							}
							
							specialStr=specialStr+temp[t]+";";
							
						}
					}
					Paginate<String> pListAdd = IntReportMainService.IRsearchValues(irReport, ratioCondiction.toString(), cols,drills, orderBy, groupBy, 50, pageindex,specialStr,dailysum);
					HashMap<String,String> keyValue=new HashMap<String,String>();
					List<String> items =pListAdd.getItems(); // 获得结果集
					items.addAll(pList.getItems());
					for (String recode : items) { // 对每一条记录提取维度值，放入对应的集合中
						StringBuilder key=new StringBuilder();
						String cells[] = recode.split(";", gbs.length + 1);
						for (int i = 0; i < gbs.length; i++) { // 维度
							key.append(cells[i].split(",")[0]);
							if(i+1<gbs.length){
								key.append("_");
							}
						}
						keyValue.put(key.toString(), cells[gbs.length]);
					}
//					log.info("keySet: "+keyValue);
					wwb = ExcelUtilNew.writeExcelCommonForIRWithRatio(tableName, response, cnameList,pList.getItems(), keyValue, gbs.length, "", dayRatio, weekRatio,statgbsindex);
					
				}else{//日环比没被勾选
					
				    wwb = ExcelUtilNew.writeExcelCommonForIR(tableName, response, cnameList, pList.getItems(), "");
				}
				ExcelUtilNew.downLoadExcel(request, response,tableName, wwb);
				return new NullResult();
				
			}
			//表格宽度
			int width = 1;
			if(cols.size() >10 && cols.size() <= 20){
				width = 2;
			}else if(cols.size() >20 && cols.size() <= 30){
				width = 3;
			}else if(cols.size() >30){
				width = 4;
			}
			model.add("width",width);
			model.add("irReport",irReport);
			model.add("dateratio",dateratio);
			model.add("isMonthSearch",irReport.getIsMonthSearch());
		}catch (Exception e) {
			e.printStackTrace();
		}
		return  ActionResult.view("intreport/"+pathid);
	}	
	
	/**
	 * 通用钻取
	 * 分四部分单表鑽取，单维度钻取，多维度钻取，多表鑽取（标记字段不等于空的都要穿过来，有主key，其他的为unactive）
	 * @return
	 * */
	@SuppressWarnings("rawtypes")
	@Path("drill/{pathid}")
	@POST
	@GET
	public ActionResult drillSearch(String pathid) {
		//获取请求信息
		HttpServletRequest request = beat.getRequest();
		final HttpServletResponse response = beat.getResponse();
		String drillString = ServletRequestUtils.getStringParameter(request,
				"drillCol", "");
		List<String> rsList = new ArrayList<String>();
		List<Integer> coltypes = new ArrayList<Integer>();// colTypes
		HashMap<String, String> reqcolsMap = new HashMap<String, String>();
		String sqlstr = "";
		int addcolssize = 0;
		IRReport irReport = new IRReport();
		HashMap<String, HashMap<String, Integer>> drillmap = new HashMap<String, HashMap<String, Integer>>();
		try {
			drillString = drillString.substring(drillString.indexOf(",") + 1,
					drillString.length());
			drillString = drillString.substring(
					drillString.indexOf(",", drillString.indexOf(",") + 1) + 1,
					drillString.length());
			int id = Integer.parseInt(pathid.split("_")[0]);
			irReport = iRReportService.getReportListByMenuId(id);// 获取报表的钻取配置信息
			List<IRDrillConfig> drillConfiglist = IRDrillConfigService
					.getListByIRid(irReport.getId());
			// 钻取关联匹配
			HashMap<String, String> Drillval = new HashMap<String, String>();
			for (int i = 0; i < drillConfiglist.size(); i++) {
				Drillval.put(drillConfiglist.get(i).getDrillname(),
						drillConfiglist.get(i).getReplayname());
			}
			// 获取需钻取字段的条件信息
			String[] reqcolslist = drillString.split("#");

			for (int i = 0; i < reqcolslist.length; i++) {
				reqcolsMap.put(reqcolslist[i].split(":")[0],
						reqcolslist[i].split(":")[1]);
			}

			String coltypestr = reqcolsMap.get("colTypes");
			sqlstr = reqcolsMap.get("sql");
			String groupString = reqcolsMap.get("groupBy");
			String nextlevel = Drillval.get(reqcolsMap.get("key"));
			if (reqcolsMap.containsKey("addcolssize")) {
				addcolssize = Integer.parseInt(reqcolsMap.get("addcolssize"));
			}
			String groupSelect = "";
			HashMap<String, Integer> groupMap = new HashMap<String, Integer>();// group字段中对应的结果集位置
			HashMap<String, Integer> drilgrop = new HashMap<String, Integer>();
			HashMap<String, Integer> drilgrop1 = new HashMap<String, Integer>();
			String gb="";
			if (groupString.length() > 0) {
				for (int i = 0; i < groupString.split(" and ").length; i++) {
					String tempstr = groupString.split(" and ")[i];
					groupSelect += tempstr.split("=")[0] + " = "
							+ tempstr.split("=")[1] + " and ";
				}

				// 替换到钻取下级,加入groupmap中判断是否可继续钻取,如果本次钻取中，下一级不可以钻取，则添加下一级，保持钻取条件的最近更新
				groupString = groupString.replace(reqcolsMap.get("key"),
						nextlevel);

				for (int i = 0; i < groupString.split(" and ").length; i++) {
					String tempstr = groupString.split(" and ")[i];
					groupMap.put(tempstr.split("=")[0].trim(),
							Integer.parseInt(tempstr.split("=")[2]));
					gb=gb+tempstr.split("=")[0].trim()+",";
				}
				gb=gb.substring(0,gb.length()-1);
				// 将下一级添加到groupBy里面去，判断groupBy里面的字段还有哪些是可以钻取的，添加到drillmap中
				Iterator iterGroup = groupMap.entrySet().iterator();

				while (iterGroup.hasNext()) {
					Map.Entry entryGroup = (Map.Entry) iterGroup.next();
					// 判断时注意，如果二级存在，则不可钻取&&!groupMap.containsKey(Drillval.get(entryGroup.getKey().toString()))
					if (Drillval.get(entryGroup.getKey().toString()) != null
							&& !checkGBDrill(entryGroup.getKey().toString(), gb, Drillval))// 如果下一级可以钻取，则添加对应的drilgrop;否则添加本级，保持钻取条件的最近更新
					{
						drilgrop.put(entryGroup.getKey().toString(),
								(Integer) entryGroup.getValue());
						drilgrop1.put(entryGroup.getKey().toString(),
								(Integer) entryGroup.getValue());
					} else if (entryGroup.getKey().toString().equals(nextlevel)) {
						drilgrop.put(entryGroup.getKey().toString(),
								(Integer) entryGroup.getValue());
						drilgrop1.put(entryGroup.getKey().toString(),
								(Integer) entryGroup.getValue());
					}
				}
				drilgrop1.put("flag", 0);
				Iterator drilgropformap = groupMap.entrySet().iterator();
				while (drilgropformap.hasNext()) {
					Map.Entry entryGroup = (Map.Entry) drilgropformap.next();
					if (Drillval.get(entryGroup.getKey().toString()) != null
							&& !checkGBDrill(entryGroup.getKey().toString(), gb, Drillval))// 如果下一级可以钻取，则添加对应的drillmap;
					{
						drillmap.put(entryGroup.getKey().toString(), drilgrop);
					} else if (entryGroup.getKey().toString().equals(nextlevel)) {// 否则添加下一级级，保持钻取条件的最近更新
						drillmap.put(entryGroup.getKey().toString(), drilgrop1);
					}
				}
			}

			// 字段信息
			if (!"".equals(coltypestr)) {
				coltypestr = coltypestr.replace("[", "");
				coltypestr = coltypestr.replace("]", "");
				for (int i = 0; i < coltypestr.split(",").length; i++) {
					String temcoltypeString = coltypestr.split(",")[i];
					temcoltypeString = temcoltypeString.trim();
					coltypes.add(Integer.parseInt(temcoltypeString));
				}
			}

			// 转换sql
			// 将group中字段组合成条件
			if (sqlstr.contains("limit")) {
				sqlstr = sqlstr.substring(0, sqlstr.indexOf("limit"));
			}
			
			String replacenextname = "";
			if (Drillval.get(nextlevel) != null)// 如果还有下一级
			{
				replacenextname = Drillval.get(nextlevel);
				sqlstr = sqlstr.replaceAll(nextlevel, replacenextname);
			} else {// 钻取条件取代
				if (sqlstr.contains("and " + nextlevel + " = 'all' and")
						|| sqlstr.contains("and " + nextlevel + " = 'all'")) {
					sqlstr = sqlstr.replaceAll("and " + nextlevel + " = 'all'",
							"");
				} else if (sqlstr.contains(nextlevel + " = 'all' and")) {
					sqlstr = sqlstr.replaceAll(nextlevel + " = 'all' and", "");
				}
			}
			String selectString = sqlstr
					.subSequence(0, sqlstr.indexOf("where")).toString();
			String whereString = sqlstr.subSequence(sqlstr.indexOf("where"),
					sqlstr.indexOf("group by")).toString();
			String groupbyString = sqlstr.subSequence(
					sqlstr.indexOf("group by"), sqlstr.length()).toString();
			sqlstr = selectString.replaceAll(reqcolsMap.get("key"),
					Drillval.get(reqcolsMap.get("key")))
					+ whereString
					+ groupbyString.replaceAll(reqcolsMap.get("key"),
							Drillval.get(reqcolsMap.get("key")));
			//添加下级钻取结果不等于all限制
			groupSelect +=Drillval.get(reqcolsMap.get("key"))+" != 'all' and ";
			// 在第一个where后面添加精确的条件
			sqlstr = sqlstr.replaceFirst("where", "where " + groupSelect);

		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.info("drill error");
			e.printStackTrace();
		}
		try {
			if (!drillString.contains("tablelist:@from"))// 单表钻取
			{

				rsList = IRDrillConfigService.getListForDrill(sqlstr, coltypes,
						irReport.getDBconfig(), drillmap);

			} else {// 跨表钻取
				String[] tablelist = reqcolsMap.get("tablelist").split("@");

				List<String> tempList = new ArrayList<String>();
				for (int i = 1; i < tablelist.length; i++)// 从第二个开始
				{
					String temptable = sqlstr.substring(
							sqlstr.indexOf("from "), sqlstr.indexOf(" where"));
					sqlstr = sqlstr.replace(temptable, tablelist[i]);
					List<String> onetableList = new ArrayList<String>();
					onetableList = IRDrillConfigService.getListForDrill(sqlstr,
							coltypes, irReport.getDBconfig(), drillmap);
					tempList.addAll(onetableList);
					// IntReportMainService.sumDataForIR();
				}

				// 对templist结果集进行整合，返回rslist结果集, 不需替换对应列的sql
				List<String> cols = new ArrayList<String>();
				HashMap<String, IRColumns> irColMap = new HashMap<String, IRColumns>();

				List<IRColumns> irColList = IRColumnsService
						.getColsByReportId(irReport.getId());
				// 获取列
				String tempcols = sqlstr.substring(0, sqlstr.indexOf(" from "));
				int endin = sqlstr.length();
				if (sqlstr.contains("order by")) {
					endin = sqlstr.indexOf("order by");
				}
				String groupby = sqlstr
						.substring(sqlstr.indexOf("group by"), endin)
						.replace("group by", "").trim();
				tempcols = tempcols.replace("select ", "").trim();
				String[] colstr = tempcols.split(",");
				for (int i = 0; i < colstr.length; i++) {
					if (colstr[i].contains(" as ")) {
						String tcol = colstr[i]
								.substring(colstr[i].indexOf(" as "))
								.replaceFirst(" as ", "").trim();
						cols.add(tcol);
					} else {
						cols.add(colstr[i].trim());
					}
				}
				// 获取irColMap
				for (IRColumns vo : irColList) {
					if ("groupBy".equals(vo.getEname())) {
						continue;
					}
					irColMap.put(vo.getEname().toLowerCase(), vo);
				}
				// groupby 单独处理
				if (!"".equals(groupby)) { // 根据groupby的分词个数 虚构对应的IRColumns
											// 默认无特殊计算SQL 类型为字符
					for (int i = 0; i < groupby.split(",").length; i++) {
						String gb = groupby.split(",")[i];
						IRColumns vo = new IRColumns();
						vo.setColType(0);
						vo.setSpecialInSql("");
						irColMap.put(gb, vo);
					}
				}

				rsList = IRDrillConfigService.getListForMupDrill(tempList,
						cols, irColMap, groupby, addcolssize);
			}
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		JSONObject json = new JSONObject();
		String json1 = "[";
		for (int i = 0; i < rsList.size(); i++) {
			JSONObject json2 = new JSONObject();
			String temrsstr = rsList.get(i);
			int resultsize = temrsstr.split(";").length - addcolssize;
			for (int j = 0; j < resultsize; j++) {
				if (coltypes.get(j) == 0) {
					String tag = temrsstr.split(";")[j].split(",")[3].trim();// 判断是否可下钻到下一级
					if ("no".equals(tag)) {
						json2.accumulate("t" + j,
								temrsstr.split(";")[j].split(",")[0]);
					} else {
						JSONObject jsontag = new JSONObject();
						jsontag.accumulate("data",
								temrsstr.split(";")[j].split(",")[0]);
						jsontag.accumulate("tag", temrsstr.split(";")[j]);
						json2.accumulate("t" + j, jsontag);
					}
				} else if (coltypes.get(j) == 1) {
					String strtem = temrsstr.split(";")[j].split(",")[0];
					json2.accumulate("t" + j, tools.comInt(strtem.trim())); // 转化为需要的类型
				} else if (coltypes.get(j) == 2) {
					String strtem = temrsstr.split(";")[j].split(",")[0];
					json2.accumulate("t" + j, tools.comFloat(strtem.trim()));
				} else if (coltypes.get(j) == 3) {
					String strtem = temrsstr.split(";")[j].split(",")[0];
					json2.accumulate("t" + j, tools.comRate(strtem.trim()));
				}
			}
			json1 += json2.toString() + ",";
		}
		if (json1.length() > 6) {
			json1 = json1.substring(0, json1.length() - 1);
			json1 += "]";

		}
		json.accumulate("data", json1);
		final JSONObject jsonresult = json;
		return new ActionResult() {
			@Override
			public void render(BeatContext beat) {
				try {
					response.setContentType("text/plain; charset=utf-8");
					PrintWriter pw = response.getWriter();
					pw.write(jsonresult.toString());
					response.flushBuffer();
					IOUtils.closeQuietly(pw);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		};
	}
	
	/** 通用图表查询
	 * @return
	 */
	@Path("chartsearch/{pathid}")
	@Check("chartirsearch")
	@POST
	@GET
	public ActionResult chartSearch (String pathid){
		return new ActionResult() {
			@Override
			public void render(BeatContext beat)  {
				HttpServletRequest request = beat.getRequest();
				HttpServletResponse response = beat.getResponse();	
				String result = "error";
				try {
					User user = spu.getUserByCookie(request);
					int chartType  = ServletRequestUtils.getIntParameter(request, "chartType", 0);
					if(chartType >  0){
						String pathid = ServletRequestUtils.getStringParameter(request, "pathId","");//路径ID
						int id = Integer.parseInt(pathid.split("_")[0]);
						IRReport  irReport = iRReportService.getReportListByMenuId(id);
						List<IRSearchConfig>  searchConfigList =   IRSearchConfigService.getListByIRid(irReport.getId());
						StringBuffer  condition = new StringBuffer();//查询where条件
						StringBuffer specialValues  = new StringBuffer();//装载特殊字段  如跨表查询的起始日期 采用K:V结构 每一类以分号 ; 隔开
						String groupBy =  ServletRequestUtils.getStringParameter(request, "groupBy","");//查询维度
						
						String dateField = null;
						for(IRSearchConfig vo : searchConfigList ){
							int typeId = vo.getSearchTypeId();   //查询类型编号
							String sename = vo.getSename() ; //查询绑定字段
							switch (typeId) {
							case 3: //时间段
								String startDate = ServletRequestUtils.getStringParameter(request, "startDate","");
								String endDate = ServletRequestUtils.getStringParameter(request, "endDate","");
								condition.append(" and "+sename+">='"+startDate+"' ");
								condition.append(" and "+sename+"<='"+endDate+"' ");
								specialValues.append("startDate:"+startDate+";");
								specialValues.append("endDate:"+endDate+";");
								specialValues.append("dateName:"+sename+";");
								dateField = sename;
								break;
							case 4: //时间点
								String searchDate = ServletRequestUtils.getStringParameter(request, "searchDate","");
								condition.append(" and "+sename+">='"+searchDate+"' ");
								dateField = sename;
								break;
							case 5: //单字段模糊查询
								String mhValue = ServletRequestUtils.getStringParameter(request,sename ,"");
								if(!"".equals(mhValue)){
									condition.append(" and "+sename+" like '%"+mhValue+"%' ");
								}else{//为空时  判定是否为向上汇总型报表  是,则特殊处理： 查询维度包含该字段时   != 'all'  不包含  = 'all'  
									String xlDetail = vo.getDetailValue();
									if(xlDetail.contains("|all")){ //判定是否为向上汇总型报表
										String tpValue = "";
										if(checkGBContains(groupBy,sename)){
											tpValue = " != 'all' ";
										}else{
											tpValue = " = 'all' ";
										}
										condition.append(" and "+sename+ tpValue );
									}
								}
								break;
							case 6://单字段精准查询
								String jzValue = ServletRequestUtils.getStringParameter(request,sename ,"");
								if(!"".equals(jzValue)){
									condition.append(" and "+sename+" = '"+jzValue+"' ");
								}else{//为空时  判定是否为向上汇总型报表  是,则特殊处理： 查询维度包含该字段时   != 'all'  不包含  = 'all'  
									String xlDetail = vo.getDetailValue();
									if(xlDetail.contains("|all")){ //判定是否为向上汇总型报表
										String tpValue = "";
										if(checkGBContains(groupBy,sename)){
											tpValue = " != 'all' ";
										}else{
											tpValue = " = 'all' ";
										}
										condition.append(" and "+sename+ tpValue );
									}
									
								}
								break;
							case 7://单字段下拉框
								String xlValue = ServletRequestUtils.getStringParameter(request,sename ,"").replaceAll("'| ", "");
								if(!"".equals(xlValue)){
									if("all".equals(xlValue)){
										xlValue = "";
									}
									condition.append(" and "+sename+" in('"+StringUtils.join(xlValue.split(","), "','") +"') ");
								}else{ //为空时  判定是否为向上汇总型报表  是,则特殊处理： 查询维度包含该字段时   != 'all'  不包含  = 'all'  
									String xlDetail = vo.getDetailValue();
									if(xlDetail.contains("|all")){ //判定是否为向上汇总型报表
										condition.append(" and "+sename+ " = 'all' " );
									}
								}
								
								break;
							case 11://展现城市级联（3级）
								int dlShowLevel = 0; //级联层数
								int dlShowType = 0; //查询类型  1：正常   2：老的向上汇总   3 .新的向上汇总
								for(String temp : vo.getDetailValue().split(";")){
									if(temp.split(":")[0].equals("level")){
										dlShowLevel = Integer.parseInt(temp.split(":")[1]);
									}else if(temp.split(":")[0].equals("type")){
										dlShowType = Integer.parseInt(temp.split(":")[1]);
									}
								}
								
								String[] dlEnames = sename.split(";");

								//一级城市
								String dlCity1 = ServletRequestUtils.getStringParameter(request,"dlCityOne" ,"").replaceAll("'| ", "");
								String dlCity2 = ServletRequestUtils.getStringParameter(request,"dlCityTwo" ,"").replaceAll("'| ", "");;
								String dlCity3 = ServletRequestUtils.getStringParameter(request,"dlCityThree","").replaceAll("'| ", "");
								//权限检查
								String operCitys = IntReportMainService.cityOperCheck(user);
								//城市未选&&权限非全部城市   则 需要根据权限进行限定条件
								if("".equals(dlCity1) && !MyStore.cityOperAll.equals(operCitys)){
									if(MyStore.cityOperZY.equals(operCitys)){ //直营
										dlCity1 = MyStore.zycitys;
									}else if(MyStore.cityOperQD.equals(operCitys)){//渠道
										dlCity1 = MyStore.cityOperQD; //渠道比较特殊  先赋予一个值 后面查询条件用not in作特殊处理
									}else { //其他
										dlCity1 = operCitys.substring(0,operCitys.lastIndexOf(","));
									}
									
								}
								//不为空则直接写入条件 ;为空则根据汇总方式进行条件判定  后面每一级都如此
								if(!"".equals(dlCity1)){ //非空
									//全部渠道城市选择特殊处理  
									if(MyStore.cityOperQD.equals(dlCity1)){
										//渠道城市  =  非直营城市  &&　不等于all(处理向上汇总型报表)
										String dlCity1Deal = " not in("+MyStore.zycitys+") and "+dlEnames[0]+" !='all' " ;
										condition.append(" and "+dlEnames[0] + dlCity1Deal);
									}else{
										String dlCity1Deal = " in('"+ StringUtils.join(dlCity1.split(","), "','")+"') " ;
										condition.append(" and "+dlEnames[0] + dlCity1Deal);
									}
								}else if(StringUtils.isBlank(dlCity2) && StringUtils.isBlank(dlCity3)){
									if(dlShowType == 2){
										condition.append(" and "+dlEnames[0]+" is null  ");
									}else if(dlShowType == 3){
											/**逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'    */
										condition.append(" and "+dlEnames[0]);
										if(checkGB(groupBy, dlEnames,0)){
											condition.append("!='all'  ");
										}else{
											condition.append("='all'  ");
										}
									}
								}
							
								if(MyStore.cityOperQD.equals(dlCity1)){
									dlCity1 = ""; //渠道城市 city1条件使用完了 要改回正常状态 否则影响后续使用
								}
								
								
								if(dlShowLevel >= 2){
									if(!"".equals(dlCity2)){
										condition.append(" and "+dlEnames[1]+" in('"+StringUtils.join(dlCity2.split(","), "','") +"') ");
									}else if(StringUtils.isBlank(dlCity3)){
										if(dlShowType == 2){
											condition.append(" and "+dlEnames[1]+" is null  ");
										}else if(dlShowType == 3){
											condition.append(" and "+dlEnames[1]);
											if(checkGB(groupBy, dlEnames,1)){
												condition.append("!='all'  ");
											}else{
												condition.append("='all'  ");
											}											
										}
									}
								}
								
								if(dlShowLevel >= 3){
									if(!"".equals(dlCity3)){
										condition.append(" and "+dlEnames[2]+" in('"+StringUtils.join(dlCity3.split(","), "','") +"') ");
									}else{
										if(dlShowType == 2){
											condition.append(" and "+dlEnames[2]+" is null  ");
										}else if(dlShowType == 3){
											condition.append(" and "+dlEnames[2]);
											if(checkGB(groupBy, dlEnames, 2)){
												condition.append("!='all'  ");
											}else{
												condition.append("='all'  ");
											}
										}
									}
								}
								break;
							case 12://归属城市级联（3级）
								int blShowLevel = 0; //级联层数
								int blShowType = 0; //查询类型  1：正常   2：老的向上汇总   3 .新的向上汇总
								for(String temp : vo.getDetailValue().split(";")){
									if(temp.split(":")[0].equals("level")){
										blShowLevel = Integer.parseInt(temp.split(":")[1]);
									}else if(temp.split(":")[0].equals("type")){
										blShowType = Integer.parseInt(temp.split(":")[1]);
									}
								}
								
								String[] blEnames = sename.split(";");
								
								//一级城市
								String blCity1 = ServletRequestUtils.getStringParameter(request,"blCityOne" ,"").replaceAll("'| ", "");
								String blCity2 = ServletRequestUtils.getStringParameter(request,"blCityTwo" ,"").replaceAll("'| ", "");
								String blCity3 = ServletRequestUtils.getStringParameter(request,"blCityThree","").replaceAll("'| ", "");
								//权限检查
								String operCitysBelong = IntReportMainService.cityOperCheck(user);
								
								//城市未选&&权限非全部城市   则 需要根据权限进行限定条件
								if("".equals(blCity1) && !MyStore.cityOperAll.equals(operCitysBelong)){
									if(MyStore.cityOperZY.equals(operCitysBelong)){ //直营
										blCity1 = MyStore.zycitys;
									}else if(MyStore.cityOperQD.equals(operCitysBelong)){//渠道
										blCity1 = MyStore.cityOperQD;
									}else { //其他
										blCity1 = operCitysBelong.substring(0,operCitysBelong.lastIndexOf(","));
									}
								}
								
								if(!"".equals(blCity1)){ //非空
									//全部渠道城市选择特殊处理  
									if(MyStore.cityOperQD.equals(blCity1)){
										//渠道城市  =  非直营城市  &&　不等于all(处理向上汇总型报表)
										String blCity1Deal = " not in("+MyStore.zycitys+") and "+blEnames[0]+" !='all' " ;
										condition.append(" and "+blEnames[0] + blCity1Deal);
									}else{
										String blCity1Deal =  " in('"+StringUtils.join(blCity1.split(","), "','") +"') " ;
										condition.append(" and "+blEnames[0] + blCity1Deal);
									}
								}else if(StringUtils.isBlank(blCity2) && StringUtils.isBlank(blCity3)){
									if(blShowType == 2){
										condition.append(" and "+blEnames[0]+" is null  ");
									}else if(blShowType == 3){
										condition.append(" and "+blEnames[0]);
										if(checkGB(groupBy, blEnames, 0)){
											condition.append("!='all'  ");
										}else{
											condition.append("='all'  ");
										}
									}
								}
								
								if(MyStore.cityOperQD.equals(blCity1)){
									blCity1 = ""; //渠道城市 city1条件使用完了 要改回正常状态 否则影响后续使用
								}
								
				
								if(blShowLevel >= 2){
									if(!"".equals(blCity2)){
										condition.append(" and "+blEnames[1]+" in('"+StringUtils.join(blCity2.split(","), "','") +"') " );  
									}else if(StringUtils.isBlank(blCity3)){
										if(blShowType == 2){
											condition.append(" and "+blEnames[1]+" is null  ");
										}else if(blShowType == 3){
											condition.append(" and "+blEnames[1]);
											if(checkGB(groupBy, blEnames, 1)){
												condition.append("!='all'  ");
											}else{
												condition.append("='all'  ");
											}
										}
									}
								}
									
								if(blShowLevel >= 3){
									if(!"".equals(blCity3)){
										condition.append(" and "+blEnames[2]+" in('"+StringUtils.join(blCity3.split(","), "','") +"') ");
									}else{
										if(blShowType == 2){
											condition.append(" and "+blEnames[2]+" is null  ");
										}else if(blShowType == 3){
											condition.append(" and "+blEnames[2]);
											if(checkGB(groupBy, blEnames, 2)){
												condition.append("!='all'  ");
											}else{
												condition.append("='all'  ");
											}
										}
									}
								}
								break;

							case 17://展现品类组件（新）- 只到3级
								int newShowLevel = 0; //级联层数
								int newShowType = 0; //查询类型  1：正常   3：向上汇总
								String showBusi = "";
								for(String temp : vo.getDetailValue().split(";")){
									if(temp.split(":")[0].equals("level")){
										newShowLevel = Integer.parseInt(temp.split(":")[1]);
									}else if(temp.split(":")[0].equals("type")){
										newShowType = Integer.parseInt(temp.split(":")[1]);
									}else if(temp.split(":")[0].equals("show")){
										showBusi = temp.split(":")[1];
									}
								}
								String[] newEnames = sename.split(";");
								
								//频道
								String dpBusinessTypeName = ServletRequestUtils.getStringParameter(request,"dpBusinessTypeName" ,"").replaceAll("'| ", "");
								String dpNewCateOne = ServletRequestUtils.getStringParameter(request,"dpNewCateOne" ,"").replaceAll("'| ", "");
								String dpNewCateTwo = ServletRequestUtils.getStringParameter(request,"dpNewCateTwo" ,"").replaceAll("'| ", "");
								String dpNewCateThree = ServletRequestUtils.getStringParameter(request,"dpNewCateThree","").replaceAll("'| ", "");

								//用户操作权限 - 业务线判定
								showBusi = IntReportMainService.businessOperCheck(user, showBusi);
								if("".equals(dpBusinessTypeName) && !"".equals(showBusi)){
									for (String temp : showBusi.split(",")) {
										dpBusinessTypeName = dpBusinessTypeName + "'" + temp+"',";
									}
									dpBusinessTypeName = dpBusinessTypeName.substring(0,dpBusinessTypeName.lastIndexOf(",")).replaceAll("'| ", "");
								}
								
								if(!"null".equals(newEnames[0].toLowerCase())){ // 表内有业务线字段的
									if(!"".equals(dpBusinessTypeName)){ //无论哪种newShowType   有值则写入条件
										condition.append(" and "+newEnames[0]+" in('"+StringUtils.join(dpBusinessTypeName.split(","), "','") +"') ");
									}else{
										if(newShowType == 3 && StringUtils.isBlank(dpNewCateOne) && StringUtils.isBlank(dpNewCateTwo) && StringUtils.isBlank(dpNewCateThree)){
											condition.append(" and "+newEnames[0]);
											if(checkGB(groupBy, newEnames, 0)){
												condition.append("!='all'  ");
											}else{
												condition.append("='all'  ");
											}
										}
									}
								}							
								
								//一级品类
																
								if(!"".equals(dpNewCateOne)){
									condition.append(" and "+newEnames[1]+" in('"+StringUtils.join(dpNewCateOne.split(","), "','")+"') ");
								}else{
									if(newShowType == 3 && StringUtils.isBlank(dpNewCateTwo) && StringUtils.isBlank(dpNewCateThree)){
										condition.append(" and "+newEnames[1]);
										if(checkGB(groupBy, newEnames, 1)){
											condition.append("!='all'  ");
										}else{
											condition.append("='all'  ");
										}
									}
								}					
								
								//二级品类
								if(newShowLevel >= 2){
									if(!"".equals(dpNewCateTwo)){
										condition.append(" and "+newEnames[2]+" in('"+StringUtils.join(dpNewCateTwo.split(","), "','")+"') ");
									}else{
										if(newShowType == 3 && StringUtils.isBlank(dpNewCateThree)){
											condition.append(" and "+newEnames[2]);
											if(checkGB(groupBy, newEnames, 2)){
												condition.append("!='all'  ");
											}else{
												condition.append("='all'  ");
											}
										}
									}											
								}
								//三级品类
								if(newShowLevel >= 3){
									if(!"".equals(dpNewCateThree) ){
										condition.append(" and "+newEnames[3]+" in('"+StringUtils.join(dpNewCateThree.split(","), "','")+"') ");
									}else{
										if(newShowType == 3){
											condition.append(" and "+newEnames[3]);
											if(checkGB(groupBy, newEnames, 3)){
												condition.append("!='all'  ");
											}else{
												condition.append("='all'  ");
											}											
										}
									}		
								}
								break;
								
							case 18://归属品类组件（新）- 只到3级
								int newBcLevel = 0; //级联层数
								int newBcType = 0; //查询类型  1：正常   3：向上汇总
								String newBcshowBuis = "";
								for(String temp : vo.getDetailValue().split(";")){
									if(temp.split(":")[0].equals("level")){
										newBcLevel = Integer.parseInt(temp.split(":")[1]);
									}else if(temp.split(":")[0].equals("type")){
										newBcType = Integer.parseInt(temp.split(":")[1]);
									}else if(temp.split(":")[0].equals("show")){
										newBcshowBuis = temp.split(":")[1];
									}
								}
								String[] newBcEnames = sename.split(";");
								
								//频道
								String bcBusinessTypeName = ServletRequestUtils.getStringParameter(request,"bcBusinessTypeName" ,"").replaceAll("'| ", "");
								String bcNewCateOne = ServletRequestUtils.getStringParameter(request,"bcNewCateOne" ,"").replaceAll("'| ", "");
								String bcNewCateTwo = ServletRequestUtils.getStringParameter(request,"bcNewCateTwo" ,"").replaceAll("'| ", "");
								String bcNewCateThree = ServletRequestUtils.getStringParameter(request,"bcNewCateThree","").replaceAll("'| ", "");
								//用户操作权限 - 业务线判定
								newBcshowBuis = IntReportMainService.businessOperCheck(user, newBcshowBuis);
								if("".equals(bcBusinessTypeName) && !"".equals(newBcshowBuis)){
									for (String temp : newBcshowBuis.split(",")) {
										bcBusinessTypeName = bcBusinessTypeName + "'" + temp+"',";
									}
									bcBusinessTypeName = bcBusinessTypeName.substring(0,bcBusinessTypeName.lastIndexOf(",")).replaceAll("'| ", "");
								}
								
								if(!"null".equals(newBcEnames[0].toLowerCase())){ // 表内有业务线字段的
									if(!"".equals(bcBusinessTypeName)){
										condition.append(" and "+newBcEnames[0]+" in('"+StringUtils.join(bcBusinessTypeName.split(","), "','") +"') ");
									}else{
										if(newBcType == 3 && StringUtils.isBlank(bcNewCateOne) && StringUtils.isBlank(bcNewCateTwo) && StringUtils.isBlank(bcNewCateThree)){
											condition.append(" and "+newBcEnames[0]);
											if(checkGB(groupBy, newBcEnames, 0)){
												condition.append("!='all'  ");
											}else{
												condition.append("='all'  ");
											}
										}
									}							
								}
								
											
								
								//一级品类
								if(!"".equals(bcNewCateOne)){
									condition.append(" and "+newBcEnames[1]+" in('"+StringUtils.join(bcNewCateOne.split(","), "','")+"') ");
								}else{
									if(newBcType == 3 && StringUtils.isBlank(bcNewCateTwo) && StringUtils.isBlank(bcNewCateThree)){
										condition.append(" and "+newBcEnames[1]);
										if(checkGB(groupBy, newBcEnames, 1)){
											condition.append("!='all'  ");
										}else{
											condition.append("='all'  ");
										}
									}
								}		
								
								//二级品类
								if(newBcLevel >= 2){
									if(!"".equals(bcNewCateTwo)){
										condition.append(" and "+newBcEnames[2]+" in('"+StringUtils.join(bcNewCateTwo.split(","), "','")+"') ");
									}else{
										if(newBcType == 3 && StringUtils.isBlank(bcNewCateThree)){
											condition.append(" and "+newBcEnames[2]);
											if(checkGB(groupBy, newBcEnames, 2)){
												condition.append("!='all'  ");
											}else{
												condition.append("='all'  ");
											}
										}
									}		
								}
								//三级品类
								if(newBcLevel >= 3){
									if(!"".equals(bcNewCateThree) ){
										condition.append(" and "+newBcEnames[3]+" in('"+StringUtils.join(bcNewCateThree.split(","), "','")+"') ");
									}else{
										if(newBcType == 3){
											condition.append(" and "+newBcEnames[3]);
											if(checkGB(groupBy, newBcEnames, 3)){
												condition.append("!='all'  ");
											}else{
												condition.append("='all'  ");
											}
										}
									}		
								}
								break;
							case 19://信息来源级联组件  （向上汇总型）
								int infoSourceLevel = 0; //级联层数数
								for(String temp : vo.getDetailValue().split(";")){
									if(temp.split(":")[0].equals("level")){
										infoSourceLevel = Integer.parseInt(temp.split(":")[1]);
									}
								}
								String[] infoSourceEnames = sename.split(";");
								
								//平台
								String infoPlatform = ServletRequestUtils.getStringParameter(request,"infoPlatform" ,"").replaceAll("'| ", "");
								String infoSourceName = ServletRequestUtils.getStringParameter(request,"infoSourceName" ,"").replaceAll("'| ", "");
								
								if(!"".equals(infoPlatform)){
									condition.append(" and "+infoSourceEnames[0]+" in('"+StringUtils.join(infoPlatform.split(","), "','") +"') ");
								}else if(StringUtils.isBlank(infoSourceName)){
									condition.append(" and "+infoSourceEnames[0]);
									if(checkGB(groupBy, infoSourceEnames, 0)){
										condition.append("!='all'  ");
									}else{
										condition.append("='all'  ");
									}									
								}
								//sourceid
								if(infoSourceLevel >= 2){
									if(!"".equals(infoSourceName)){
										condition.append(" and "+infoSourceEnames[1]+" in('"+StringUtils.join(infoSourceName.split(","), "','") +"') ");
									}else{
										condition.append(" and "+infoSourceEnames[1]);
										if(checkGB(groupBy, infoSourceEnames, 1)){
											condition.append("!='all'  ");
										}else{
											condition.append("='all'  ");
										}	
									}
								}
								break;
								
								
							case 20://流量来源级联组件  （向上汇总型）
								int flowSourceLevel = 0; //级联层数数
								for(String temp : vo.getDetailValue().split(";")){
									if(temp.split(":")[0].equals("level")){
										flowSourceLevel = Integer.parseInt(temp.split(":")[1]);
									}
								}
								String[] flowSourceEnames = sename.split(";");
								//一级来源
								String flowSourceOne = ServletRequestUtils.getStringParameter(request,"flowSourceOne" ,"").replaceAll("'| ", "");
								//二级来源
								String flowSourceTwo = ServletRequestUtils.getStringParameter(request,"flowSourceTwo" ,"").replaceAll("'| ", "");
								//三级来源
								String flowSourceThree = ServletRequestUtils.getStringParameter(request,"flowSourceThree" ,"").replaceAll("'| ", "");
								//四级来源
								String flowSourceFour = ServletRequestUtils.getStringParameter(request,"flowSourceFour" ,"").replaceAll("'| ", "");
								
								
								if(!MyStore.admin.equals(user.getFunction())){ //管理员权限不用校验
									HashSet<Long> userOpersSet = userOperService.getUserOpers(user.getId());//用户全部细粒度权限
									List<OperMenu> operList = userOperService.getOperListByCate("流量数据统计", "流量来源一级渠道"); //该系列所有正常数据权限
									
									String checkFowSourceOne = "";
									for (OperMenu operMenu : operList) {
										long operid = operMenu.getId();
										String operName = operMenu.getName();
										if(userOpersSet.contains(operid)){
											if(operid == 9){ //所有一级来源
												break;
											}else{
												if("".equals(flowSourceOne)){ //全选时
													checkFowSourceOne = checkFowSourceOne + "'" + operName+"',";
												}
											}
										}
									}
									
									if("".equals(flowSourceOne)){ //全选时
										flowSourceOne = checkFowSourceOne;
									}
									if(flowSourceOne.endsWith(",")){
										flowSourceOne = flowSourceOne.substring(0,flowSourceOne.lastIndexOf(",")).replaceAll("'| ", "");
									}
								}
								

								if(!"".equals(flowSourceOne)){
									condition.append(" and "+flowSourceEnames[0]+" in('"+StringUtils.join(flowSourceOne.split(","), "','") +"') ");
								}else if(StringUtils.isBlank(flowSourceTwo) && StringUtils.isBlank(flowSourceThree) && StringUtils.isBlank(flowSourceFour)){ 
									condition.append(" and "+flowSourceEnames[0]);
									if(checkGB(groupBy, flowSourceEnames, 0)){
										condition.append("!='all'  ");
									}else{
										condition.append("='all'  ");
									}
								}
								
								if(flowSourceLevel >= 2){
									if(!"".equals(flowSourceTwo)){
										condition.append(" and "+flowSourceEnames[1]+" in('"+StringUtils.join(flowSourceTwo.split(","), "','") +"') ");
									}else if(StringUtils.isBlank(flowSourceThree) && StringUtils.isBlank(flowSourceFour)){ // 向上汇总报表   
										condition.append(" and "+flowSourceEnames[1]);
										if(checkGB(groupBy, flowSourceEnames, 1)){
											condition.append("!='all'  ");
										}else{
											condition.append("='all'  ");
										}
									}
								}
								
								if(flowSourceLevel >= 3){
									if(!"".equals(flowSourceThree)){
										condition.append(" and "+flowSourceEnames[2]+" in('"+StringUtils.join(flowSourceThree.split(","), "','") +"') ");
									}else if(StringUtils.isBlank(flowSourceFour)){ // 向上汇总报表   
										condition.append(" and "+flowSourceEnames[2]);
										if(checkGB(groupBy, flowSourceEnames, 2)){
											condition.append("!='all'  ");
										}else{
											condition.append("='all'  ");
										}
									}
								}
								
								if(flowSourceLevel >= 4){
									if(!"".equals(flowSourceFour)){
										condition.append(" and "+flowSourceEnames[3]+" in('"+StringUtils.join(flowSourceFour.split(","), "','") +"') ");
									}else{ // 向上汇总报表   
										condition.append(" and "+flowSourceEnames[3]);
										if(checkGB(groupBy, flowSourceEnames, 3)){
											condition.append("!='all'  ");
										}else{
											condition.append("='all'  ");
										}										
									}
								}

								break;
								
							case 21://驾校一点通来源级联组件  （向上汇总型）
								int jxedtSourceLevel = 0; //级联层数数
								for(String temp : vo.getDetailValue().split(";")){
									if(temp.split(":")[0].equals("level")){
										jxedtSourceLevel = Integer.parseInt(temp.split(":")[1]);
									}
								}
								String[] jxedtSourceEnames = sename.split(";");
								
								//source1
								String jxedtSourceOne = ServletRequestUtils.getStringParameter(request,"jxedtSourceOne" ,"").replaceAll("'| ", "");
								String jxedtSourceTwo = ServletRequestUtils.getStringParameter(request,"jxedtSourceTwo" ,"").replaceAll("'| ", "");
								if(!"".equals(jxedtSourceOne)){
									condition.append(" and "+jxedtSourceEnames[0]+" in('"+StringUtils.join(jxedtSourceOne.split(","), "','") +"') ");
								}else if(StringUtils.isBlank(jxedtSourceTwo)){
									condition.append(" and "+jxedtSourceEnames[0]);
									if(checkGB(groupBy, jxedtSourceEnames, 0)){
										condition.append("!='all'  ");
									}else{
										condition.append("='all'  ");
									}
								}
								//source2
								if(jxedtSourceLevel >= 2){
									if(!"".equals(jxedtSourceTwo)){
										condition.append(" and "+jxedtSourceEnames[1]+" in('"+StringUtils.join(jxedtSourceTwo.split(","), "','") +"') ");
									}else{
										condition.append(" and "+jxedtSourceEnames[1]);
										if(checkGB(groupBy, jxedtSourceEnames, 1)){
											condition.append("!='all'  ");
										}else{
											condition.append("='all'  ");
										}
									}
								}
								break;
								
							case 22:
								int chrFlowSourceLevel = 0; //级联层数数
								for(String temp : vo.getDetailValue().split(";")){
									if(temp.split(":")[0].equals("level")){
										chrFlowSourceLevel = Integer.parseInt(temp.split(":")[1]);
									}
								}
								String[] chrFlowSourceEnames = sename.split(";");
								
								//一级来源  
								String chrSourceOne = ServletRequestUtils.getStringParameter(request,"chrSourceOne" ,"").replaceAll("'| ", "");
								String chrSourceTwo = ServletRequestUtils.getStringParameter(request,"chrSourceTwo" ,"").replaceAll("'| ", "");
								String chrSourceThree = ServletRequestUtils.getStringParameter(request,"chrSourceThree" ,"").replaceAll("'| ", "");
								String chrSourceFour = ServletRequestUtils.getStringParameter(request,"chrSourceFour" ,"").replaceAll("'| ", "");
								if(!"".equals(chrSourceOne)){
									condition.append(" and "+chrFlowSourceEnames[0]+" in('"+StringUtils.join(chrSourceOne.split(","), "','") +"') ");
								}else if(StringUtils.isBlank(chrSourceTwo) && StringUtils.isBlank(chrSourceThree) && StringUtils.isBlank(chrSourceFour)){
									condition.append(" and "+chrFlowSourceEnames[0]);
									if(checkGB(groupBy, chrFlowSourceEnames, 0)){
										condition.append("!='all'  ");
									}else{
										condition.append("='all'  ");
									}
								}
								
								
								//二级来源
								if(chrFlowSourceLevel >= 2){
									if(!"".equals(chrSourceTwo)){
										condition.append(" and "+chrFlowSourceEnames[1]+" in('"+StringUtils.join(chrSourceTwo.split(","), "','") +"') ");
									}else if(StringUtils.isBlank(chrSourceThree) && StringUtils.isBlank(chrSourceFour)){
										condition.append(" and "+chrFlowSourceEnames[1]);
										if(checkGB(groupBy, chrFlowSourceEnames, 1)){
											condition.append("!='all'  ");
										}else{
											condition.append("='all'  ");
										}
									}
								}
								
								
								//三级来源
								if(chrFlowSourceLevel >= 3 ){
									if(!"".equals(chrSourceThree)){
										condition.append(" and "+chrFlowSourceEnames[2]+" in('"+StringUtils.join(chrSourceThree.split(","), "','") +"') ");
									}else if(StringUtils.isBlank(chrSourceFour)){
										condition.append(" and "+chrFlowSourceEnames[2]);
										if(checkGB(groupBy, chrFlowSourceEnames, 2)){
											condition.append("!='all'  ");
										}else{
											condition.append("='all'  ");
										}
									}
								}
								
								
								//四级来源
								if(chrFlowSourceLevel >= 4 ){
									if(!"".equals(chrSourceFour)){
										condition.append(" and "+chrFlowSourceEnames[3]+" in('"+StringUtils.join(chrSourceFour.split(","), "','") +"') ");
									}else{
										condition.append(" and "+chrFlowSourceEnames[3]);
										if(checkGB(groupBy, chrFlowSourceEnames, 3)){
											condition.append("!='all'  ");
										}else{
											condition.append("='all'  ");
										}
									}
								}
								break;
								
							case 23://中华英才行业级联组件  （向上汇总型）
								int chrIndustryLevel = 0; //级联层数数
								for(String temp : vo.getDetailValue().split(";")){
									if(temp.split(":")[0].equals("level")){
										chrIndustryLevel = Integer.parseInt(temp.split(":")[1]);
									}
								}
								String[] chrIndustryEnames = sename.split(";");
								
								//一级来源  
								String chrIndustryOne = ServletRequestUtils.getStringParameter(request,"chrIndustryOne" ,"").replaceAll("'| ", "");
								String chrIndustryTwo = ServletRequestUtils.getStringParameter(request,"chrIndustryTwo" ,"").replaceAll("'| ", "");
								
								if(!"".equals(chrIndustryOne)){
									condition.append(" and "+chrIndustryEnames[0]+" in('"+StringUtils.join(chrIndustryOne.split(","), "','")+"') ");
								}else if(StringUtils.isBlank(chrIndustryTwo)){
									condition.append(" and "+chrIndustryEnames[0]);
									if(checkGB(groupBy, chrIndustryEnames, 0)){
										condition.append("!='all'  ");
									}else{
										condition.append("='all'  ");
									}
								}
								
								
								//二级来源
								if(chrIndustryLevel >= 2){
									if(!"".equals(chrIndustryTwo)){
										condition.append(" and "+chrIndustryEnames[1]+" in('"+StringUtils.join(chrIndustryTwo.split(","), "','")+"') ");
									}else{
										condition.append(" and "+chrIndustryEnames[1]);
										if(checkGB(groupBy, chrIndustryEnames, 1)){
											condition.append("!='all'  ");
										}else{
											condition.append("='all'  ");
										}
									}
								}
								break;
								
							case 24://中华英才职位级联组件  （向上汇总型）
								int chrJobLevel = 0; //级联层数数
								for(String temp : vo.getDetailValue().split(";")){
									if(temp.split(":")[0].equals("level")){
										chrJobLevel = Integer.parseInt(temp.split(":")[1]);
									}
								}
								String[] chrJobEnames = sename.split(";");
								
								//一级来源  
								String chrJobOne = ServletRequestUtils.getStringParameter(request,"chrJobOne" ,"").replaceAll("'| ", "");
								String chrJobTwo = ServletRequestUtils.getStringParameter(request,"chrJobTwo" ,"").replaceAll("'| ", "");
								String chrJobThree = ServletRequestUtils.getStringParameter(request,"chrJobThree" ,"").replaceAll("'| ", "");
								if(!"".equals(chrJobOne)){
									condition.append(" and "+chrJobEnames[0]+" in('"+StringUtils.join(chrJobOne.split(","), "','") +"') ");
								}else if(StringUtils.isBlank(chrJobTwo) && StringUtils.isBlank(chrJobThree)){
									condition.append(" and "+chrJobEnames[0]);
									if(checkGB(groupBy, chrJobEnames, 0)){
										condition.append("!='all'  ");
									}else{
										condition.append("='all'  ");
									}
								}
								
								
								//二级来源
								if(chrJobLevel >= 2){
									if(!"".equals(chrJobTwo)){
										condition.append(" and "+chrJobEnames[1]+" in('"+StringUtils.join(chrJobTwo.split(","), "','") +"') ");
									}else if(StringUtils.isBlank(chrJobThree)){
										condition.append(" and "+chrJobEnames[1]);
										if(checkGB(groupBy, chrJobEnames, 1)){
											condition.append("!='all'  ");
										}else{
											condition.append("='all'  ");
										}
									}
								}
								
								
								//三级来源
								if(chrJobLevel >= 3 ){
									if(!"".equals(chrJobThree)){
										condition.append(" and "+chrJobEnames[2]+" in('"+StringUtils.join(chrJobThree.split(","), "','") +"') ");
									}else{
										condition.append(" and "+chrJobEnames[2]);
										if(checkGB(groupBy, chrJobEnames, 2)){
											condition.append("!='all'  ");
										}else{
											condition.append("='all'  ");
										}
									}
								}
								
								break;
							}
						
						}
						
//						String comparGB = "";
						String comparGB = StringUtils.strip(groupBy, ", ");
						String chartValues = ServletRequestUtils.getStringParameter(request,"chartvalues","");//选择的指标
						if(StringUtils.isBlank(chartValues)){
							chartValues = ServletRequestUtils.getStringParameter(request,"colsSelect","").replaceAll("'| ", "");
						}
						List<IRColumns>  irColList = IRColumnsService.getColsByReportId(irReport.getId());
						Map<String,String>  dicMap = new HashMap<String,String>();
						for(IRColumns column : irColList){
//							dicMap.put(column.getCname(), column.getEname());
							dicMap.put(column.getEname(), column.getCname());
						}
						
						List<String> cols = new ArrayList<String>(); //查询显示字段
						List<String> chartCols = new ArrayList<String>(); //查询显示字段
						if(!"".equals(comparGB)){
							cols.add("groupBy");
							
							int xIndex = 0; //X轴对应的字段在 维度中的序号。默认去第一个。
							String[] bgArr = comparGB.split(",");
							int groupCount = bgArr.length;
							for(int i=0 ; i< groupCount ; i++){ 
								chartCols.add("groupBy");
								if(bgArr[i].equals(dateField))								
									xIndex = i;
							}
							for(String eValue : chartValues.split(",")){
								if(dicMap.containsKey(eValue)){
									cols.add(eValue);
									chartCols.add(eValue);
								}
							}
							
							
							int pageindex = -1; //数据全查
							Paginate<String> pList = IntReportMainService.IRsearchValues(irReport, condition.toString(), cols,null, " order by "+comparGB, comparGB, 50, pageindex,specialValues.toString(),1);
							//流量来源报表  来源字段需要通过对应的中英文字典翻译
							int menuId = irReport.getMenuId();
							if(!pList.getItems().isEmpty() && (menuId>=269 && menuId <= 272) && groupBy.contains("source") ){
								pList = IntReportMainService.flowSourceNameTran(pList);
							}
							switch (chartType) {
							case 1: //曲线图 （多指标 单时间轴）
								result = EChartsUtils.transRS2Lines(pList.getItems(), chartCols, dicMap,xIndex);
								break;
							case 2: //饼图（比例图）
								result = EChartsUtils.transRS2Pie(pList.getItems(), chartCols, dicMap);
//								result = fcu.XMLForIRbyPie(pList.getItems());
								break;
							}
						}
					}
				} catch (Exception e) {
					e.printStackTrace();
				}finally{
					try{
						response.setContentType("text/plain; charset=utf-8");
						PrintWriter pw = response.getWriter();
						pw.write(result);
//						System.err.println(result);
						response.flushBuffer();
						IOUtils.closeQuietly(pw);
					}catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		};
	}


	
	/**检查查询维度里 是否 包含该指标 （完全匹配)
	 * @param groupBy   like  1:stat_date,11:pagetype,13:channel
	 * @param checkName
	 * @return
	 */
	private boolean checkGBContains(String groupBy ,String checkName){
		boolean rs = false;
		
		String[] gbtemps = groupBy.split(",");
		for (String temp : gbtemps) {
			if(temp.contains(":")){
				temp = temp.substring(temp.indexOf(":") + 1);
			}
			
			if((checkName.toLowerCase()).equals(temp.toLowerCase())){
				return true;
			}
		}
		
		return rs;
	}
	
	/**
	 * 逻辑 : 检查查询维度是否包含本级或任意次级   一旦包含则  条件  !='all'  否则就  条件 = 'all'
	 * @return
	 */
	private boolean checkGB(String groupBy ,String[] dlEnames, int index){
		boolean flag = false;
		
//		for(int i = 0 ; i < dlEnames.length; i ++){
//			String check = dlEnames[i];
			if(groupBy.contains(dlEnames[index])){
				flag = true;
//				break;
			}
//		}
		return flag;
	}
	
	
	/**检查查询维度里 该指标 是否可钻取（完全匹配),返回可钻取的集合
	 * @param groupBy   
	 * @param drills
	 * @return
	 */
	private boolean checkGBDrill(String checkname,String groupBy,HashMap<String, String> drillsMap){
		boolean rs = false;
		while (drillsMap.get(checkname)!=null) {
			checkname=drillsMap.get(checkname);
			if(checkGBContains(groupBy,checkname))
			{
				return true;
			}	
		}
		return rs;
	}
}
